DotDragnet
May 24, 2012, 07:46:50 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Excluding categories from home.php in Wordpress  (Read 661 times)
Matt
DDN Contribs
Hero Member
*****
Posts: 1710



View Profile WWW Awards
« on: October 17, 2011, 08:11:29 AM »

I am using the following code in home.php, above the loop to exclude posts from the home loop if in a certain category

I have two problems :-

- when using this piece of code my pagnation no longer works. It changes the URL but seems to just start the loop again
- If a post is in two categories, and one is the excluded category, it wont show. Is there a way to say only exclude if it is only in the specified category.


Code:
<?php
if (is_home()) {
query_posts("cat=-176");
}
?>

Thanks in advance
Logged

sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #1 on: October 17, 2011, 10:12:40 AM »

http://www.dynamicwp.net/articles-and-tutorials/pagination-problem-when-excluding-certain-category-from-blog-main-page/ for the pagination issue smile

You could try the different styles of exclusion for categories on the WP_Query page, maybe one of those will do what you need - http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Possibly the category__not_in

Alternatively, if it's straightforward enough to do (ie. those who write posts to be excluded can grasp the method), why not tag the post or give it a custom field that you then use to exclude from the front page?
Logged

robthedog
Newbie
*
Posts: 7



View Profile Awards
« Reply #2 on: October 17, 2011, 10:16:02 AM »

To sort your paging try:

Code:

<?php
$args
=array(
'cat'=> -176,
'paged'=> get_query_var('paged')
);

query_posts($args);
?>



As for the first problem, could you not have a 'featured' category or tag to determine if the post is displayed, rather than excluding a category?

Logged
Matt
DDN Contribs
Hero Member
*****
Posts: 1710



View Profile WWW Awards
« Reply #3 on: October 17, 2011, 03:19:23 PM »

To sort your paging try:

Code:

<?php
$args
=array(
'cat'=> -176,
'paged'=> get_query_var('paged')
);

query_posts($args);
?>



As for the first problem, could you not have a 'featured' category or tag to determine if the post is displayed, rather than excluding a category?



Thanks Rob, that worked like a charm. Brilliant Stuff.
Logged

robthedog
Newbie
*
Posts: 7



View Profile Awards
« Reply #4 on: October 17, 2011, 05:08:03 PM »

No probs, glad to be able to help  smile
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!