WordPress.org

Ready to get started?Download WordPress

Forums

Complex category exclusion/display on homepage (3 posts)

  1. stellar23
    Member
    Posted 3 years ago #

    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.

  2. tugbucket
    Member
    Posted 3 years ago #

    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; ?>
  3. stellar23
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic