How to restrict categories in WP?

Status
Not open for further replies.

-Bill-

Earth Emperor
Feb 29, 2008
509
3
0
C'dale
Im trying to figure out how to restrict specific categories from displaying in the recent news module. How can I do it?
 


What do you mean by "recent news module"?

So you're saying you have a recent news category and you don't want other category posts showing up in there? Is recent news a parent category of some other categories? Or is it a latest posts thing? (widget).

It's probably a simple fix but I'm not sure I understand the question.
 
Last edited:
This is just the default Latest posts widget that comes on most themes. The title (although it can be changed) of it is Recent News

I've messed with a bunch of stuff and did a few sample posts to try and get it right but its a no go so far.

Put it this way - I have general articles, and product reviews. I want the general articles to show in the "recent news" widget, but I do not want the product reviews to be visible in the same widget.

Thanks for your response abhorrent
 
This is just the default Latest posts widget that comes on most themes. The title (although it can be changed) of it is Recent News

I've messed with a bunch of stuff and did a few sample posts to try and get it right but its a no go so far.

Put it this way - I have general articles, and product reviews. I want the general articles to show in the "recent news" widget, but I do not want the product reviews to be visible in the same widget.

Thanks for your response abhorrent
Go to wordpress.com and go to the search page. check the box underneath the search input box for "forums" and type in "specify category" and run through the links until you find the relevant category tag for whatever version of WordPress you're using. One of these will invariably link to the codex explaining how the "the_category()" [or whichever particular loop call you need] will allow you to specify categories.

There's no one exact answer - it depends on how your widget performs the category sort, what version of WordPress you're using and other stuff. I'm not being a smart ass with this answer, but without exposing your code it's going to be hard to get someone to do your homework on this.
 
Thank you on-on
Didn't come off as an asshole at all.
I was hoping someone could just point me to where I could find relevant info and go from there.
Again, Thanks man, I will check it out.
 
There's no one exact answer - it depends on how your widget performs the category sort, what version of WordPress you're using and other stuff. I'm not being a smart ass with this answer, but without exposing your code it's going to be hard to get someone to do your homework on this.
Most of this stuff never changes. Unless he's using an extremely modified template or something it should all be standard wp stuff.

So Bill,
Here's what you do.
In your "wp-includes" folder find widgets.php

Back up your widgets.php file though just in case!

Find this line (Line 821 when I open it in dreamweaver).
$options = get_option('widget_recent_entries');
About 8 lines below that you'll see this...
$r = new WP_Query("showposts=$number&what_to_show=posts&nopaging=0&post_status=publish");
At the end of that lie add &cat=CATID (CATID being your category ID number).

If you only want to show one category do it as..
&cat=CATID

If you want to just exclude a category, do it as &cat=-CATID (Note minus sign)
It will be easier to just include the one you want, especially if you have a lot of categories.

So basically if your News category was category 1 the string would look like this...

$r = new WP_Query("showposts=$number&what_to_show=posts&nopaging=0&post_status=publish&cat=1");
Give that a try and let me know. It should work.
Back up your widgets.php file though just in case!
 
Last edited:
That was good advice.

Most of this stuff never changes. Unless he's using an extremely modified template or something it should all be standard wp stuff.
They do try to stay consistent, but a fair amount of stuff changes version to version - I mentioned what I mentioned specifically because the other day I ran into the deprecation of one of the functions that I hadn't played with in a while and of course because 2.5 changed a lot of functions (someone maintains a list up to 2.3 here).
 
Thanks a lot for the in-depth how to abhorrent, I appreciate it.
I'll test it out when I get time and let you know how it worked.

I have fewer excludes than includes...
For multiples of either, how do I combine it?
&cat=-1,-3,-4
&cat=-1&cat=-2

Coming into WP not knowing anything about PHP, and being able to sift through and modify stuff is really helping me learn PHP gradually.

Thanks for all your help
 
I have fewer excludes than includes...
For multiples of either, how do I combine it?
&cat=-1,-3,-4
&cat=-1&cat=-2

Coming into WP not knowing anything about PHP, and being able to sift through and modify stuff is really helping me learn PHP gradually.

Thanks for all your help
You're welcome and yes, You'd do it like the above in yellow to do more than one.
 
Status
Not open for further replies.