Forums

[resolved] COnditional Headers For Individual Entries (4 posts)

  1. 4evrblu
    Member
    Posted 3 years ago #

    I use the following code as a mini-header of sorts for each entry.

    <div class="allposts"><p>You are watching <?php the_title(); ?> from the <?php the_category(', '); ?> series. Watch <?php the_title(); ?> and the other episodes of <?php the_category(', '); ?> with online anime streaming only here at HiddenAnime. </p></div>

    I have 5000 entries at my site and here is a sample page in a sandbox that you can view to see what I am trying to do:

    http://plussizedfitness.com/blog/?p=1

    The sandbox is not set up with fancy permalinks, but that will not matter for the purposes of this discussion.

    What I need to do is exclude the above mini-header tag from a category called "old_anime" and because I am not educated in PHP very well, I sure could use some help.

    The mini-header tag is in the single post,php content loop, so that it appears in every entry. So, how do I write a conditional statement to exclude it from the stated category?

    Thank you

  2. jcow
    Member
    Posted 3 years ago #

    Wrap the code that you don't want to show on posts in the particular category in these two bits of code:

    <php if( !in_category('category_name') ): ?>

    and

    <?php endif; ?>

    make sure to change category_name.

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

  3. 4evrblu
    Member
    Posted 3 years ago #

    OK, this is getting me there. But how can I get the category name displayed with WordPress coding it as a hypertext link? In other words, just display the non-linked category names?

    Here is what I now have:

    <?php if( in_category(204) || in_category (185) || in_category (181) ) : ?>
    
    <?php else : ?>
    <div class="allposts">You are watching <?php the_title(); ?> from
    the <?php the_category(', '); ?> series. Watch <?php the_title(); ?>
    and the other episodes of <?php the_category(', '); ?> with online
    anime streaming only here at HiddenAnime.
    </div>
    <?php endif; ?>

    This works, but it ends up displaying linked categories that are clickable.

    Like so:

    http://www.hiddenanime.com/bokura-ga-ita-22/

  4. converting2wp
    Member
    Posted 3 years ago #

    You mean "without WordPress coding it ..."?

    Replace your
    <?php the_category(', '); ?>

    with

    <?php
    foreach((get_the_category()) as $category) {
        echo $category->cat_name . ' ';
    }
    ?>

    or something a little trickier if you want a comma after each category but the last.

    See http://codex.wordpress.org/Template_Tags/get_the_category

Topic Closed

This topic has been closed to new replies.

About this Topic