PDA

View Full Version : Exclude a specific category


david
February 23rd, 2006, 02:36
Which is the easiest way on K2 to exclude a specific category from the main page (and subsequent pages, i.e. /page/2/, /page/3/, etc), but show it (the category and posts within) when going to it from archives and such?

I Google It(tm) over and over and none of the solutions I found worked on 2.0.1. Shed some light, anyone?

Thanks!

JohnW.
February 23rd, 2006, 04:41
Open index.php and add the code below.
<?php
if (is_home()) {
query_posts("cat=-15");
}
?>
Right above this.
<?php include (TEMPLATEPATH . '/theloop.php'); ?>
Then just change the number in the query to the ID of the category you don't want showing up. You can go to Manage > Categories in the admin area to find the ID of the category.

david
February 23rd, 2006, 05:22
JohnW, that removes the posts within the category -which is great, just what I want-, but also breaks pagination. I now get always the same frontpage posts, when I hit "previous entries", even though pages incremenent (i.e. /page/2/, /page/3/ and so on).

Help?

david
February 24th, 2006, 12:38
Any further thoughs anyone? Michael, any ideas of why this is breaking pagination? Thanks in advance.

JohnW.
February 24th, 2006, 05:42
Sorry, didn't realize that it broke pagination. :( Open up theloop.php and find this line
<?php /* Normal Entries */ } elseif (!(in_category($k2asides))) { ?>
And replace with this, changing 13 to whichever category you want to block.
<?php /* Normal Entries */ } elseif (!(in_category($k2asides)) && !(in_category('13')) or is_archive() or is_search() or is_single()) { ?>

david
February 24th, 2006, 06:09
Sorry, didn't realize that it broke pagination. :( Open up theloop.php and find this line
<?php /* Normal Entries */ } elseif (!(in_category($k2asides))) { ?>
And replace with this, changing 13 to whichever category you want to block.
<?php /* Normal Entries */ } elseif (!(in_category($k2asides)) && !(in_category('13')) or is_archive() or is_search() or is_single()) { ?>

That worked, John! Thanks so much!

Clappie
May 10th, 2006, 02:43
Maybe someone could help me (i tried every plugin, using K2):

I want to show the last 2 posts from only ONE special category on my frontpage with full content(like only the last 2 posts from the 'news' category).

My site in developping: http://weblog.mehost.nl/ (now its showing the last 2 post from any category)

Using WordPress 2.0.2 .. so maybe you guys know what to enter in the loop. The solution above doesnt work for me :(

rafik
July 6th, 2008, 10:50
Hi,
In newest K2 this solution is not working anymore. Could somebody be glad and write instruction:
How exclude a specific Category from showing on main page?
Best regards
Rafał