The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Sub Category "Tree" Problem

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #25713

    I’m working on a blog that uses categories for the navigation. its for a school and each part of the school has its own category, every post gets assigned the right cat and then only shows up in its section etc.

    Each category has an image in the sidebar that changes as you navigate through.

    problem is, when you go to the "Middle School" it shows the correct image in the sidebar, then when you click on a post, it shows the default image. my php isnt pulling the category despite it being in the url still. any ideas on how i can do this?

    Get the parent category of a post and display the correct image?

    here’s the code:


    (The above image shows if on any page that doesnt have an
    assigned category. Ex: Archives, search & Home)


    any ideas guys?


    Moved to CMS section, might get more looks here.


    is_category() is only true if the current page is the category’s archive page, so it won’t help you if you want to style a single post page.

    To determine if the current post has a certain category assigned you can use in_category(). E.g.

    if (in_category(‘middle-school’)) : /* do stuff */ endif;

    A simpler solution might involve putting what you want to appear in the side bar in the category’s description and simply using the following in your single.php:

    $category = get_the_category();
    if (isset($category[0]))
    echo $category[0]->category_description;

    Hope that helps!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.