• Resolved katootje

    (@katootje)


    Hi,

    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.
    Anyone??

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:

    <?php
    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>

    Thread Starter katootje

    (@katootje)

    Thnxx, the first line is working perfect!

    How can I put the categories links?

    thanks

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