Don't display Post Title for specific category (3 posts)

  1. Riles
    Posted 4 years ago #

    I am trying to add some code to single.php that will show the post title (heading) for posts in all categories except one, but after trying loads of options I have to admit defeat. I would really appreciate some help.

    Here's what I have so far:

    <div class="cs-article">
    $cat = get_the_category();
    if (in_array("Events",$cat)): ?>
    <?php //print_r($cat); ?>
    <?php else: ?>
    <h2 style="margin-top:15px;">
    <span class="cs-PostHeader"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>">
    <?php the_title(); ?>
    <?php endif; ?>

    I would think that if the post is in the 'Events' category then this code should work, but it doesn't. I used print_r() to see what is output for get_the_category() and 'Events' is in the array, but the code creates the same result for all posts.
    I also tried turning the array into a string using implode() and then looking for 'Events' in the string, but implode() throws p an error.

    Thanks so much for your time!

  2. Michael
    Forum Moderator
    Posted 4 years ago #

  3. Riles
    Posted 4 years ago #

    Thanks so much alchymyth - in_category() is exactly what I was looking for!

Topic Closed

This topic has been closed to new replies.

About this Topic