Ready to get started?Download WordPress


[resolved] Show parent of category in archive (4 posts)

  1. katootje
    Posted 7 years ago #


    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.

  2. Kafkaesqui

    Posted 7 years ago #

    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>
  3. katootje
    Posted 7 years ago #

    Thnxx, the first line is working perfect!

  4. Roberto Simões
    Posted 6 years ago #

    How can I put the categories links?


Topic Closed

This topic has been closed to new replies.

About this Topic