Indentify a posts category ? (3 posts)

  1. thornomad
    Posted 9 years ago #


    I want my viewers to get different page content based on the category of the post(s) they are viewing. I am able to get special "top text" information for when they view a category, but how I can adjust the sidebar content and then top category to match a particular single post as well?

    What are the functions I need to have it run an if/else on the post itself and determine its category ? Thanks

    Currenly, in my index.php file I have:

    <?php if (have_posts()) : ?><br />
    <?php $post = $posts[0]; ?><br />
    <?php if (is_category()) { ?><br />
    <h2 class="pagetitle"><?php echo single_cat_title(); ?> - <?php echo category_description(); ?></h2><br />
    <?php } elseif (is_search()) { ?><br />
    <h2 class="pagetitle">Search Results</h2><br />
    <?php } else { ?><br />
    <h2 class="pagetitle">Download free music and audiobooks and read the blog<br />All content written and performed by Damon Timm</h2><br />
    <?php } ?>

  2. Kafkaesqui

    Posted 9 years ago #

    Check out the in_category() function.


    For use in the sidebar, see the info on using it outside The Loop:


  3. thornomad
    Posted 9 years ago #

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.