• Hey,
    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">
    <?php
    $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(); ?>
    </a></span>
    </h2>
    <?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!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Don't display Post Title for specific category’ is closed to new replies.