Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter displayname

    (@displayname)

    bump

    Is there any way to get the category ID on a page

    .

    What do you mean by page? For a given posts, for a given category archive?

    Thread Starter displayname

    (@displayname)

    Basically I want to incorporate the category id in the following code:

    <?php
    $category = wp_list_categories('style=none&echo=0&child_of=4&depth=1&title_li=');
    $category = preg_replace('/(<a)/','<div class="item"><div class="background"></div><a href="https://example.com/?cat=' . CATEGORY ID . '"><img src="https://example.com/images/' . CATEGORY ID . '" alt="' . $category->cat_name . '" /></a><div class="content"><h2><a',$category);
    $category = str_replace('</a>', '</a></h2></div></div>', $category);
    echo $category;
    ?>

    I’m using this code on the index.php outside of the Loop and want to display the categories with the specified style and an image where the image will be from the url https://example.com/images/CATIDHERE . So, each category has its own thumbnail image linking to the category.php.

    Using $category->cat_id doesn’t work. I’ve also tried $wp_query->get_queried_object_id but when I use that, the category ID would be the same for all categories (I don’t know why) and so the thumbnail would become the same for the different categories.

    Please help.

    How about this:

    <?php
    $cats=get_categories ();
    foreach ( (array) $cats as $cat ) {
    echo 'id = ' . $cat->cat_ID . ' name =' . $cat->name . ' count = ' .$cat->count ;
    }
    ?>

    how about get_query_var('cat')

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get Category ID (numerical)??’ is closed to new replies.