Monday, March 5, 2012

Solving is_home() problem in Wordpress

I have a Wordpress site built on the Pagelines framework and wanted to exclude posts from all categories but one on the homepage and have been struggling with it for about an hour now.  I totally overlooked the fact that the query had to be reset before it would function correctly.

What was happening was no matter which page or category I was on it would only display the single category.  Here's what you need to do in order to get it working right (in your functions.php file).



function exclude_blog_cat() {
 wp_reset_query();
 global $query_string; 
 if (is_home()) { 
  query_posts($query_string.'cat=-1, -5, -6, -7, -8'); 
  }
}
add_action('pagelines_before_theloop', 'exclude_blog_cat');

No comments:

Post a Comment