Support » Themes and Templates » Show parent of category in archive

  • Resolved katootje



    I like to show the parent categoryname on the archive page of a child category. I think i have to add something to this line:
    <h2 class=”pagetitle”>Archive for the ‘<?php single_cat_title(); ?>’ Category</h2>

    I just want to change it in:
    <h2 class=”pagetitle”><?php here the code for the parent /> – <?php single_cat_title(); ?></h2>

    I’ve look everywhere but can’t find what to put there.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can do this by collecting the category parent ID from the query object and using get_the_category_by_ID() to display it:

    global $wp_query;
    $category = $wp_query->get_queried_object();
    <h2 class="pagetitle"><?php echo get_the_category_by_ID($category->parent); ?> - <?php single_cat_title(); ?></h2>
    To test for it, change your <code><h2></code> to:
    <h2 class="pagetitle"><?php if( $category->parent ) { echo get_the_category_by_ID($category->parent) . ' - '; } single_cat_title(); ?></h2>

    Thnxx, the first line is working perfect!

    How can I put the categories links?


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show parent of category in archive’ is closed to new replies.