Cheesetoast » exclude http://www.cheesetoast.co.uk Brain Food for Web Developers Mon, 07 Jul 2014 23:18:22 +0000 en-US hourly 1 http://wordpress.org/?v=4.2.13 Exclude Category from WordPress RSS Feed http://www.cheesetoast.co.uk/exclude-categories-wordpress-rss-feed/ http://www.cheesetoast.co.uk/exclude-categories-wordpress-rss-feed/#comments Tue, 28 Aug 2012 19:21:15 +0000 http://www.cheesetoast.co.uk/?p=665 A useful little code snippet to remove categories from the Wordpress RSS feed. Continue reading

The post Exclude Category from WordPress RSS Feed appeared first on Cheesetoast.

]]>
A useful little code snippet to remove categories from the WordPress RSS feed.

Just add the following code to your function.php file:

function exclude_RSS_cat($query) {
if ($query->is_feed) {
$query->set('cat','-12');
}
return $query;
}

add_filter('pre_get_posts','exclude_RSS_cat');

This will remove the category with the ID of 12.

The post Exclude Category from WordPress RSS Feed appeared first on Cheesetoast.

]]>
http://www.cheesetoast.co.uk/exclude-categories-wordpress-rss-feed/feed/ 4
Exclude Category from WordPress Blog Page http://www.cheesetoast.co.uk/exclude-include-category-wordpress-blog-page/ http://www.cheesetoast.co.uk/exclude-include-category-wordpress-blog-page/#comments Mon, 27 Aug 2012 18:37:26 +0000 http://www.cheesetoast.co.uk/?p=642 Often when designing Wordpress themes you'll want to exclude certain post categories from appearing in your blog page. Luckily it's very easy to do. Continue reading

The post Exclude Category from WordPress Blog Page appeared first on Cheesetoast.

]]>
Often when designing WordPress themes you’ll want to exclude a category from your blog page. Luckily it’s very easy to do.

Open up your index.php file (or whichever file you’re using to display your blog posts) and add this line of code right before the loop:

<?php query_posts('cat=-12'); ?>

Add the code right before this line:

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

This will exclude the category with id of 12.

If you want to exclude more than one category you can use:

<?php query_posts('cat=-4,-12,-14'); ?>

Include a specific category

If you only want to include a certain category you just remove the minus character from the query:

<?php query_posts('cat=12'); ?>

Additional arguements

You can also add additional arguments to the query. In this example I will only display posts from a specific category and time period:

<?php query_posts('cat=12&year=2012'); ?>

You can take this a step further and only display posts from the current month by adding some php:

<?php query_posts( $query_string . '&cat=13&monthnum=' . date( 'n', current_time( 'timestamp' ) ) ); ?>

There are plenty of other arguments available to further filter your posts. Read more from the WordPress Codex: Query Posts.

The post Exclude Category from WordPress Blog Page appeared first on Cheesetoast.

]]>
http://www.cheesetoast.co.uk/exclude-include-category-wordpress-blog-page/feed/ 0