WordPress.org

Support

Support » Plugins and Hacks » Hacks » Complex category exclusion/display on homepage

Complex category exclusion/display on homepage

  • I’m a total newbie so apologies if this is not the right place to ask this.

    I have a site with 2 categories (News and Press) and several static pages. On the home page I would like to display all my News posts and certain Press posts (ie those that I categorise as both News and Press).

    I know I can exclude all Press posts using the Advanced Category Excluder
    Plug in but this doesn’t give me quite the functionality I am looking for. I’ve looked at WP_query() and think it might be possible using this but my PHP is limited to say the least – hoping someone is willing to help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • This will only display posts in the News category. Since the posts that you want to show from the Press category are also in the News category, it will show them as well.

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if (in_category('news')) { ?>
    
    	<div class="post" id="post-<?php the_ID(); ?>">
    		<div class="post-header">
    			<h2><?php the_title(); ?></h2>
            </div>
    		<div class="meta">
            	<p>Posted Under <?php the_category(' ') ?></p>
            </div>
    	</div>
    <?php } ?>
    <?php endwhile; ?>
    <?php else: ?>
    <?php endif; ?>

    Thank you so much. I thought using a plug in for this was using a sledgehammer to crack a nut.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Complex category exclusion/display on homepage’ is closed to new replies.