WordPress.org

Ready to get started?Download WordPress

Forums

Indentify a posts category ? (3 posts)

  1. thornomad
    Member
    Posted 8 years ago #

    Hi,

    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 8 years ago #

    Check out the in_category() function.

    http://codex.wordpress.org/Template_Tags/in_category

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

    http://codex.wordpress.org/Template_Tags/in_category#Use_OUTSIDE_The_Loop

  3. thornomad
    Member
    Posted 8 years ago #

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.