Check if a category is in the_category?

  • Unknown's avatar

    What I’ve got at the moment to see if a category is currently a category of the post that you’re currently viewing is:

    <ul>
    <?php
    	if (in_array("Advertising",get_the_category()))
    		{$posts = query_posts('cat=8&showposts=3&random=true'); }
    	elseif (in_array("Branding",get_the_category()))
    		{$posts = query_posts('cat=12&showposts=3&random=true'); }
    	elseif (in_array("Campaigns",get_the_category()))
    		{$posts = query_posts('cat=16&showposts=3&random=true'); }
    	elseif (in_array("Interactive",get_the_category()))
    		{$posts = query_posts('cat=20&showposts=3&random=true'); } ?>
    <?php while (have_posts()) : the_post(); ?>
    	<?php { ?>
    	<li>
    	<h4><a href="<?php echo get_permalink($post->ID); ?>">
                <?php echo $post->post_title; ?></a>
            </h4>
    	<?php echo c2c_get_custom('Tease'); ?>
    	<img class="featured_thumb" src="<?php echo nggallery::get_image_url( get_post_meta($post->ID, 'featured_image_id', true) ); ?>" width="56" height="56" alt="" />
    	</li>
    	<?php } ?>
    <?php endwhile; ?>
    </ul>

    Any hints?

  • Unknown's avatar

    Since you are self-hosted, go to http://wordpress.org/support/ . This is a free-hosting service and we know nothing about the underlying wordpress or theme files. We don’t even have access to them.

  • Unknown's avatar
  • The topic ‘Check if a category is in the_category?’ is closed to new replies.