Jump to content


Photo

Need help to eliminate certain posts categories from showing up in Blog


  • Please log in to reply
11 replies to this topic

#1 piccante

piccante

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 16 May 2011 - 12:07 PM

Guys, need help in excluding certain posts categories from showing up in the Blog section and "latest posts entries" widget in the StationPro theme. Ive included a query_posts( 'cat=-4' ); in the index.php of the theme (StationPro) but it works partially. Thanks...

#2 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts
  • Country: Country Flag

Posted 16 May 2011 - 09:27 PM

Can you tell us more about the code you've used...Typically if you want to make this only affect certain pages such as the main blog then you would add conditionals e.g. ` if(is_home()): query_posts( 'cat=-4' ); endif; `

#3 piccante

piccante

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 16 May 2011 - 10:41 PM

Well, specifically Ive put the query_posts( 'cat=-4' ); in the index.php of the theme and it works when the "Blog" page is accessed. But I have 2 issues: 1. In the widget (from _morefooter) where the latest posts are shown (mine is 3, just the titles) I still see the posts from the category that is supposed to be excluded. 2. When the "Blog" page is accessed in the summary of the posts the excluded category's posts are not visible, but when each individual post is accessed then the "prev" or "next" posts might be of the excluded category. Is there a remedy for this ? Thanks...

#4 catrina

catrina

    Advocate

  • Members
  • 12345 posts
  • LocationCalifornia
  • Country: Country Flag

Posted 17 May 2011 - 02:33 AM

Hm, I know there's a way to exclude a category from a list of categories but not specific posts belonging to a category in a list of posts. There might be a solution for it somewhere on the web. I did some searching and found this: http://wordpress.org...nt-posts-widget

#5 piccante

piccante

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 17 May 2011 - 11:28 PM

Thanks, but my issue is not the code its exactly where does it need to go. The widget that Im using on the homepage is the: Recent Posts I need to be able to exclude one category from showing up in the "most recent 3 posts" widget.

#6 catrina

catrina

    Advocate

  • Members
  • 12345 posts
  • LocationCalifornia
  • Country: Country Flag

Posted 18 May 2011 - 02:09 AM

Can you post a link to your site? I think I confused the "Recent Posts" widget with something else, but I'm pretty sure it's the widget that lists the post link titles...

#7 timlinson

timlinson

    Advocate

  • Members
  • PipPipPipPipPip
  • 1032 posts

Posted 18 May 2011 - 03:36 AM

my issue is not the code its exactly where does it need to go

query_posts() won't affect the widgets regardless of where you put it.

You can use a php exec plugin and make your own recent posts widget with some php code. This is one example:
http://forum.bytesfo...hread.php?t=865

#8 piccante

piccante

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 18 May 2011 - 05:02 AM

Tim, I see maybe it makes sense just to implement my own code. I thought there was a way to do it through the widget, but yeah I've tried everything and the widget was still showing the excluded Category. Now, I still see the post in the "Blog" singles pages. For instace lets say Im in a given category the "next" post might show a post from the excluded category. Do you guys know why ? Thanks...

#9 timlinson

timlinson

    Advocate

  • Members
  • PipPipPipPipPip
  • 1032 posts

Posted 18 May 2011 - 05:16 AM

For instace lets say Im in a given category the "next" post might show a post from the excluded category. Do you guys know why ?

This involves messing with WP's previous_post_link() call.

e.g.
http://wordpress.org...-next_post_link

#10 piccante

piccante

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 18 May 2011 - 05:31 AM

Yes, I've actually find the code that exclude the post from excluded categories in the single post "prev" and "next" posts in wp-includes/link-template.php function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '4') { adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true); } /** * Display next post link that is adjacent to the current post. * * @since 1.5.0 * * @param string $format Optional. Link anchor format. * @param string $link Optional. Link permalink format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '4') { adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false); } It worked for me! So now I will just have to exclude the posts from excluded categories in the Recent Posts Widget. I think I will either use an excluder plugin or right my own.

#11 piccante

piccante

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 18 May 2011 - 06:03 AM

Ok, found a plugin that exclude categories from pages and widgets "ACE". I guess this is it. I got everything that I need. Thanks alot guys for your help. Thanks...

#12 wendygordon

wendygordon

    Super Member

  • Members

  • 153 posts
  • Country: Country Flag

Posted 02 February 2012 - 03:12 PM

can you tell us what is the plugin? does it work on the posts page to exclude posts from a particular category?