• I’m looking for code that looks at the current page category, then loops through and outputs the linked title of each subcategory, as well as pulling the featured image from the first post in that subcategory… Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter shiningpathos

    (@shiningpathos)

    Shucks, just figured it out –

    <?php $categories = get_categories("child_of=17"); foreach ($categories as $cat) { ?>
    	<h2><a href="<?php get_category_link(); ?>"><?php single_cat_title(); ?></a></h2>
    		<?php endwhile; ?>
    <?php }?>

    But: the only issue is that get_category_link is wrong here. It just links to the parent. I need that h2 to link into its respective child category. Any clues?

    Thread Starter shiningpathos

    (@shiningpathos)

    Got it –

    <h2><a href="<?php echo get_category_link($cat);?>"><?php single_cat_title(); ?></a></h2>

    Thread Starter shiningpathos

    (@shiningpathos)

    Heh, actually wait, I’ve got one more question –

    I want to use this code in various places throughout my theme, so the “child_of=17” parameter is not going to work. What’s a more generic way to say, “Child of the current page?”

    the current category archive page’s category ID is:

    get_query_var('cat')

    Thread Starter shiningpathos

    (@shiningpathos)

    Thanks – but where would I include that?

    Thread Starter shiningpathos

    (@shiningpathos)

    Also, could anyone tell me how to add the category description for each? I added this-

    <?php echo category_description($cat);?>

    That only seems to work if I replace $cat with a specific ID number. But I need it to by dynamic. Thanks!

    Thread Starter shiningpathos

    (@shiningpathos)

    Doh, never mind. The $cat is unnecessary.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘"Give me links to every subcategory of the current page category…"’ is closed to new replies.