headerIMG

B2B Articles - Sep 9, 2009 4:37:22 PM

How to limit or exclude categories for Wordpress frontpage blog posts

Wordpress Help and HintsWe have been asked a few times by bloggers how to limit or exclude categories from your Wordpress installation frontpage. By default Wordpress will display a stream of blog posts from all categories. Some bloggers may wish to not display certain categories in that stream of posts on their homepage. A few web designers asked us how to control or exclude specific categories that should not be displayed.

Our answer was to write the code for the theme, and not edit the core functionality since that would complicate WP updates.

In the index.php file of your theme, there is a Loop statement. Wordpress processes this Loop statement for each of the posts in your blog. The statement begins with this code snippet:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

The loop ends with this piece of code:

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Here is one way to solve this problem. This will allow you to limit specific categories from your frontpage and publish the remaining categories automatically. We will try to expand upon this post soon and explain other options and this option in more detail. The numbers "1", "3", "5", and "7" are the categories to be excluded from the frontpage blog.

<?php while (have_posts()) : the_post(); ?>
<?php if (!in_category('1') && !in_category('3') && !in_category('5') && !in_category('7')) { ?>

POST CODE GOES HERE
<? } ?>
<?php endwhile; ?>

Tel 212-993-7809  

Ironpaper ®
10 East 33rd Street 
6th Floor
New York, NY 10016
Map

Ironpaper - B2B Agency

B2B Marketing and Growth Agency.

Grow your B2B business boldly. Ironpaper is a B2B marketing agency. We build growth engines for marketing and sales success. We power demand generation campaigns, ABM programs, create B2B content, strengthen sales enablement, generate qualified leads, and improve B2B marketing efforts.

Ironpaper Twitter Ironpaper Linkedin