Building Your Website, Step-By-Step

RYO ‘Category Visibility’ WordPress Plugin

I needed a plugin that would display Posts only from certain categories. I found an earlier version of this plugin and modified it for my needs; then I supercharged it. Now I'm sharing it with you.

A good example of Category Visibility is this very website. It's original purpose (in 2005) was to serve my web customers, most of whom wouldn't have any idea how to install a plugin. I didn't want plugin Posts to show to my regular users, but wanted to make the plugins available to other WordPress users who would want them.

See all of our WordPress Plugins

I created a WP Plugins category and unchecked "Front" and "List." This kept these Posts off the home page, and the listing off the sidebar. (That's all changed now. Users have a much greater understanding of plugins!)

The "WordPress Plugins" link above illustrates the point. It's a link to the category page, which lists the plugins. You can see the category page and the associated Posts just fine. But that category did not show up in the sidebar, or on the home page. (It does now.)

This way, you could get access, in fact, anyone can search for them and find them. But they were not "out there" on the home page or in category links in the sidebar bothering my regular users.

Screenshot

RYO Category Visibility Options Page

History

I was using a WordPress plugin called Category Visibility (Keith McDuffee) which was written for WordPress 1.5.

It had a few odd points like when it filtered posts off the Home Page that was okay but it didn't replace them; that is, if your front page was supposed to show 10 posts and two were filtered out, you'd only get eight posts. I fixed that and a few other tricky things.

It was wonderful, and lots of users agreed. Then WordPress 2.1 came out and broke everything. So I stuck with WP 2.0 for a long time.

No more! I woke in the middle of the night with an idea on how to re-think the logic and rewrite the whole thing from scratch. The new approach is more concise and takes fewer resources.

The result is faster, leaner, and, I hope, more likely to work with newer versions of WP. The same, familiar interface. Far more efficient.

Multiple categories on a post? Fine. The plugin tells WP which categories to exclude. This might not always be what you want. But it's how it works.

There's no upgrade path. If you're using an older Category Visibility from one of the folks who tried to upgrade the old code, uninstall that first.

Instructions

  1. Simply download the zip file.
  2. At your website dashboard, go to Plugins, Add New, then find and install the plugin.
  3. Activate it.
  4. Go to RYO Plugins, RYO Category Visibility to see the visibility settings for all categories. the options are:
  • Front: Posts show up on the main (home) page.
  • List: Categories that will show up in the List of categories in the sidebar. (Or, probably in any list based widget.)
  • Search: Posts show up in search results.
  • Feed: Posts show up in the main RSS/Atom feed.
  • Archive: Posts show up in archive pages (i.e., clicking on the calendar links).
  • User Level: Numeric user level required to see these Posts. (Yes, I know this is deprecated, but I've left it in for folks who want it.)

Everything is checked to show up by default.

When you have a category to exclude from the front page, or the sidebar, etc., go to "Manage," "Category Visibility," and deselect the areas where you want the category to disappear.

This method is not designed as a security device, only as a display method. A guest can still access a post by post number.

Download

Download for WP: The latest version.

 

598 Responses to RYO ‘Category Visibility’ WordPress Plugin

1 2 3 12
  • Hi,

    I was trying to get the Private Categories 2 plugin to work on my site, but it kept breaking in IE.

    Found your plugin through a search and it works like a charm!

    Great work and thanks!

  • Thanks, it seems the original author has dropped this project. Your work is very much appreciated.

  • Update: I found a bug.

    You need to add support for child categories. That is, categories that are made under a parent.

    If you get that fixed it is perfect.

  • Thanks a lot for updating this essential plugin!!! I was starting to be afraid that I’d have to rebuild my whole site until I read your message at gudlyff’s.

    And many thanks also for your improvements, specially for the default visibility for new categories.

    Maira

  • Thanks, all.

    Luis, caught the child cat bug. (Would a child cat be a kitten?) Squished the bug and uploaded v. 1.0.0a.

    Maira, thanks. That drove me nuts. Also, when you’d set up a new system and activated the plugin everything was fouled up til you went in and initialized the database. Now it’s created when you activate the plugin.

    Rich

  • Category Visibility seemed to be creating a lot of mysql queries, so I modified it a bit to cache results and it made a difference. In my somewhat high-overhead theme it reduced the query count by about 18, which I consider significant.

    So, if you want a Category Visibility that runs faster, download 1.0.0b.

    Rich

  • Great! I also ran into the Filter problem with Keith’s plugin. This one worked as a out of the box replacement.

    THX
    Martin

  • Thanks for carrying on with this plugin. It’s of definite value.

    Any chance you’ll add support for turning on/off visibility of pages for wordpressers using list_pages or wp_list_pages in their sidebar. It would be great not to have to muck around in code in order to display/exclude particular pages.

    Thanks!

  • Rena,

    About “..support for turning on/off visibility of pages for wordpressers using list_pages or wp_list_pages in their sidebar…”

    I think that would be a different animal. (Not a catt plugin.) You’d have to check for a specific custom field or template to exclude the Page from the list.

  • found another bug.

    When you have multiple loops set up on your front page, your plugin does not just kill the category from showing up in main loop, it kills them from showing up in any loop on the front page.

    one plugin i found that avoided this was: RumCategory,
    however, it is not nearly as robust as this one, therefore i would hope that you could arrange it to only kill the main loop in index.php

  • Upon further inspection, i have found that this issue is only created when making the “archive” invisible, all of the other options behave as they should when un-ticked.

    The solution is in somehow allowing users to hide posts from the archive, without completley eliminating the category all together (which is what the plugin in is seemingly doing ).

  • Well, we could debate whether or not that’s a bug, but that would serve no clear purpose.

    It’s our intention that when you uncheck something off the front page, that it is, in fact, off the front page.

    The ‘list’ is supposed to refer to the sidebar.

    We run two loops on many of our fromt pages, the first is the main loop, the second is an “additional headlines” loop. We expect excluded categories to be excluded there, too.

    I can understand that there might be cases where you’d want something else. You’d probably need to modify your index.php to set some kind of a a flag and modify the Category Visibility plugin to not react when the flag is set.

    Now it just recognizes that it’s the home page (through a process of elimination) and works accordingly.

    About the archives business, that has created a number of perplexing situations. We’ve somehow fixed most of them, but a few persist. I’ll probably go look at that sometime; can’t promise when.

    Note that there’s a little internal function in there now called cv_visible_cats(). It takes one parameter, a string that says front, list, seach, feed, or archives, defaulting to front. This returns an array of categories visible to the respective area.

    It might be possible to use that for special purposes; we do that.

    // cats visible to front page
    $acats = cv_visible_cats('front');
    $catlist = '';
    foreach ($acats as $category) {
    $catlist .= ' ' . $category->cat_ID;
    }

  • hmm, not quite sure if i know how to implement that the right way, however i have used this in conjuction with your plugin by not hiding anything from the archives in your UI, and then going in and hiding them manually in my index.php

    here is a sample of my code:

    < ?php if (is_category()) { ?>
    <h2>< ?php _e('Archive for'); ?> < ?php echo single_cat_title(); ?>

    < ?php } elseif (is_month()) {

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("paged=$paged&cat=0,1,2,3,4,5,6,7,8,9,10,11"); ?>

    <h2>< ?php _e('Archive for'); ?> < ?php the_time('F, Y'); ?>

    basically i am telling wordpress what categories to show at any given time, whatever category numbers arent listed above, are not displayed. This however is a hassle, so please fix yours :P

    hope this helps

  • When the plugin is activated, and i turn off certain categories from the archives it still displays the months where the certain categories are but then when the months are clicked on it says the page you are looking for is not there. Is there a way to make the month not be displayed if the category is turned off?

  • Great plug-in! Thanks.

    I think I’ve found a problem though; I have a category with a apostrophe in its name: ‘Jobs I’ve Known’. With the plug-in operational that category does not show up in the sidebar (even though all the checkboxes are ‘on’). If I edit the category name to remove the apostrophe, the category appears correctly. Any way around this?

    Mike

  • Thank you so much!

  • Awesome!

    Thanks Rich, just about perfect. What would be great is to have a ‘per post’ option. Meaning that when I write my post I can set whether I want it on the front page or not (but still have it publish to cats). There is something similar to this in mambo/joomla.

    Thanks anyway. Great plugin, easy to use!

    Rick.

  • Excellent plugin!
    However – for those of us looking for extra discretion, it would be even more excellent if there was a way to turn off visibility in the calendar as well. I have a test category “invisible” and deselected all of the visibility options for it, but the post I just wrote in that category still causes that day (today, 6/15) on the calendar to become a link, and a mouseover shows the title of the post. Just a thought for any future revision – suggestions for a hack welcome. :-)

  • This is very sweet. I was wracking my brain (and the support forums) trying to figure this out until someone linked me here. I haven’t implemented it yet, but just reading, it’s exactly what I was looking for. Keep me posted of any updates!

  • D’oh! I just installed it, and as I was doing so I thought to myslef “hmmm, I wonder if this is going to work with Sideblog 2.0 (By Kates Gasis)” and sure enough, it doesn’t. Had both activated and it snafu’d on yours, deactivated Sideblog and the main page works but now no ‘updates’ sideblog in the sidebar. Any thoughts?

  • It doesn’t work well with Sideblog.

  • I don’t use sideblog, but I get the following error using Ver. 1.0.0c on WP 2.0.3:

    WordPress database error: [Not unique table/alias: 'wp_post2cat']
    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) LEFT JOIN wp_catt_visibility ON (wp_post2cat.category_id = wp_catt_visibility.catt_ID) LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1 AND post_date_gmt <= '2006-06-17 09:52:59' AND (post_status = "publish" OR post_author = 1 AND post_status != 'draft' AND post_status != 'static') AND post_status != "attachment" AND ((wp_catt_visibility.front=1 AND wp_catt_visibility.cv_user_level<=10) OR post_status='static' OR wp_catt_visibility.catt_ID IS NULL) AND (category_id = 2) AND (post_end_date >= '2006-06-17 23:59:59' OR post_end_date IS NULL) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 6

    Any ideas what is going on? All I need to do is NOT allow a couple of my categories in the main blog RSS feeds.

  • Yoyo, you’ve got the same problem as JP with Sideblog, something’s combining the calls so you end up with two LEFT JOIN wp_post2cat statements in the join portion of the query.

    It’s probably some other plugin that adds the second LEFT JOIN without checking that one’s already been put into play. (In CatVis we check that before adding the join.)

  • Hi, thanks for the great plugin. However, it doesn’t seem to work when multiple categories are assigned to a post (e.g. one removed from index page, while another is not).

    Is there any way so that a post can be removed from the front page as long as one of its categories has been set as invisible?

    Thanks in advance.

  • Alas, this is one major flaw with the visibility issue… one I hope to have time to tackle sometime.

    In fact, there’s more to it than that.

    Some folks, like you, think a post shouldn’t appear if ANY category is set to invisible, and others think it should be visible if ANY category would make it visible.

    I happen to fall in the latter group.

    Suppose you have a post that’s appropriate for “members” and for “evaluators.”

    You’d want it to appear for evaluators even if members was restricted from the home page. Or sidebar list. Or whatever. Well, that’s what I’d think.

    But, as it is, mysql picks one and uses that. So with multiple categories, anything can happen.

    Sorry about that.

  • Brilliant!!!! I’ve been trying to solve this problem for days, was pointed to your plugin and voila. Done in 5 seconds. Peace, Love and Plug-ins!

  • Thank you. This is excellent work and should be referenced on the WP website for plugins. Had to search for a couple of hours and even install the original version before finding this one. I have an “Opinion” catagory, where I like to vent once in a while, but I don’t want to force people to read it when they first hit my page (only if they really want to subject themselves to my point of view).

    Thanks again for all the time you spent developing this and making it available for everyone.

  • I am using K2 and widgets plugin for the sidebar and I also have your plugin activated.

    When I click a catergory at the sidebar, I get the following error:

    [Unknown table ‘wp_post2cat’ in on clause]
    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_catt_visibility ON (wp_post2cat.category_id = wp_catt_visibility.catt_ID) WHERE 1=1 AND post_date_gmt <= ‘2006-06-26 00:57:59’ AND (post_status = “publish” OR post_author = 2 AND post_status != ‘draft’ AND post_status != ‘static’) AND post_status != “attachment” AND ((wp_catt_visibility.archives=1 AND wp_catt_visibility.cv_user_level<=10) OR post_status=’static’ OR wp_catt_visibility.catt_ID IS NULL) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 5

    When I turn off your plugin.. everything goes back to normal. Any advise?

    Thanks

  • Kelvin, I think version c will help… download it!

  • Works like a charm! I needed a solution like this… a five second google search, a ten second read of some WP Forum posts, a quick download, a quick install… it took less than five minutes to have a problem, find a solution, install it, and have the problem solved.

    Days like this, I really love the internet — and folks like you, who create plugins and offer them for free to the community. Great job.

  • Rich, thanks for the tip, the c version works!

  • there are some issues with David Coppits Category Order (http://www.coppit.org/code/) This will keep on working, whilie his hide all the cats if this is installed.

  • Just like everyone else said, this solved a problem I had been pulling my hair out about for hours – excluding more than one category from the front page with “query posts” is more difficult than it has to be!

    But this is even better. Thanks!

  • This plugin is great :) But I’m wondering if it’s possible to still show a hidden category in a seperate section of the page ie. I have two loops running, one for a devoted category, dont want to kill it all together.

  • Great plugin. One minor problem – it doesn’t hide the posts in my sidebar. I have created a “privatetest” post allocated to a “private” category to test and this post doesn’t appear on the home page, but does appear in the sidebar.

    My sidebar code is below:

    Recent Posts

    <ul class="posts">
    <?php BX_get_recent_posts($p,20); ?>
    <A href="http://www.marcuscake.com/sitemap/">View all posts (sitemap)</a>
    </ul>

    I suspect the BX_get_recent_posts function may not be typical.

    The following is from the BX_functions.php file:

    function BX_get_recent_posts($current_id, $limit)
    {
    global $wpdb;
    $posts = $wpdb->get_results(
    "SELECT ID, post_title FROM "
    . $wpdb->posts . " WHERE post_status='publish'
    AND post_category=='17' ORDER BY post_date DESC LIMIT " . $limit);
    foreach ($posts as $post) {
    $post_title = stripslashes($post->post_title);
    $permalink = get_permalink($post->ID);
    if ($post->ID != $current_id) echo "<li><a>" . $post_title . "</a></li>\n";
    }
    }

    Can anyone make any suggestions? Thanks for your help in advance.

  • Just as info:
    I also had the conflicet with two LEFT JOIN.
    Did a disable of the plugin ‘Front Page Categories’ (ok plugin, but manual edit in php file).

    Very fine plugin you made here.
    Regards

  • gracias justo lo que estaba buscando!!

  • Excellent! Worked like a charm. :)

  • I’m using your plugin. But all the posts in the hided category appears in the rss feed, and you can read all that posts with a direct link.

  • Hi,

    I’ve got the same problem. The category is hided, but in the rss feed the post appears-

    is there any fix for that problem?

  • i have same problem with sideblog, i realy need both (sideblog and catvis) what can i do?

  • Franco and Florian, when I uncheck “Feed” the stories disappear from the RSS feed. If you’re not getting that behavior, it must be due to some other plugin or modification on your system.

    Hadi, sorry, we have no solution here for plugins that don’t use the standard hooks.

  • Woohoo! Worked like a charm! Nothing can describe my relieve now. Heh heh… until it breaks (have not checked the feeds, search, etc.), of course. =P

    Well done!

    • WP 2.0.3
  • Oh, just one problem.

    If some smart alec did something like http://myblog.com/category/private , apparently all the private entries will appear. Any idea?

    Cheers!

  • Hi Rich

    Just wondering if this Category Visibility plugin can be made to work with Subscribe2 plugin – what I need to happen is the list of categories in the subscription page to be restricted by the level of the user, as would happen anywhere else on the site, but not in the admin panel it seems.

    To be more general – I want to be able to restrict the categories shown to a user even in the admin panel. Is this at all possible?

  • Upekshapriya, you might try editing the source code. As it is, the admin panel gets everything.

    CatVis has never been a “security” feature, actually, more of a “display appropriate material” kind of thing.

    That said, in version c, around line 205, are a couple of lines that you might try commenting out.

  • Just discovered that neither version seems to be working on a post in a category that’s restricted to user level 10 under a couple of conditions (when logged out completely).

    The post is shown in the sidebar when I list the titles of the latest posts with wp_get_archives(‘type=postbypost&limit=5’)

    Using the permalink to the post provided by above condition the post shows fine on its own.

    Thought that might interest you

  • Rich, sorry I didn’t see you post before I wrote the next one.

    Tried what you suggested in commenting out lines 205 and 206 to no effect. Also commented out 189 which had the same reference. This didn’t work either (ie all these lines were commented out). Maybe it’s a lot more complicated to do it?

  • Hi Rich,

    Oh, I forgot to mention that I was using v1.0.0c that allowed readers to key in the URL http://myblog.org/category/private to read all the posts in what apparently is a private category.

    However, it seems that v1.0.0b didn’t have this problem. When readers tried something like that above, they have a page not found response, which is perfect.

    May I know which is the expected behavior?

    Cheers!

  • Hi Rich,

    Thanks for the plugin. Works very well until I use it with Category Order v1.9.4 by david Coppit. Not only do I need to hide a category from the side bar, but I need to put them in a specific order.

    Andy ideas?

    Best regards!

1 2 3 12

Leave a Reply

Your email address will not be published. Required fields are marked *

Member Center
UserID:

Password:


Ads

Your Own Dot-Com Domain
cinderelladomains.com
Our Recommended Source for Securing Your Domains. Fast Registration, Direct Support Phone

Reliable Website Hosting
siteground.com
Small businesses often use Shared Hosting and the "GrowBig" plan. Free LetsEncrypt SSL included.

Create Your Own Graphics
razataz.com/graphicshb
Website headers and banners are easy to do yourself when you have this inexpensive tool!

Do Your Own Webinars
webinarjeo.com
Unlimited Webinars. Unlimited Attendees. Unlimited Scalability. True Live-Streaming Performance