Hiding a Single Category

There are a number of different slideshows out there that require you to post the images into a category that you select, this makes updating the slideshow easy to manage, one problem with this is that you cannot hide the posts, if you make the post private then the gallery stops, lets have a look at how we can suppress the slideshow gallery in our Artisteer theme.

We have used this in the our wedding theme, the cu3er slideshow  WordPress plugin from 18Elements uses a category to feed the display, when we added the images the slideshow category and the posts appeared, not a problem if the images form a part of a full post, but messy when used as placeholders.

View: The Wedding Theme.

We could hardcode the category ID and exclude this, that is fine on a static theme where we already know the Category ID, but what if we wanted to make the theme available to other clients or for free download.

On looking for a solution for our Artisteer theme to return a category ID we could not find a simple WordPress function to use on the lists, we have to create our own function that returns a value from the database, if you have been following our tutorials then you will already have demo-functions.php file, if not you can add them to the Artisteer functions.php file.

Add to either your demo-functions.php or the Artisteer theme functions.php

function demo_get_categoryID($catName){
 global $wpdb;
 $category_slug = str_replace(" ","-",$catName);
 $category_slug = strtolower($category_slug);
 $thevalue = $wpdb->get_var( "SELECT term_id FROM $wpdb->terms WHERE slug = '" . $category_slug . "'" );
 if ($thevalue) {
 return $thevalue;
 }else{
 return "";
 }
}

Now we need to filter the categories list to exclude the slideshow category from the menu, you can change the name as required.

In the Artisteer theme functions.php we will add this block of code to the code that returns the categories list, look for this line and insert the code below.

Find: wp_list_categories(‘title_li=’); and replace with the following lines.

/* Start demo Category add line */
 $exclude = demo_get_categoryID('slideshow');
 if ($exclude){
 wp_list_categories('title_li=&exclude='.$exclude.'');
 }else{
 wp_list_categories('title_li=');
}
/* End demo Category add line */

So your code block should look like this:

add_action('get_terms', 'art_vmenu_get_terms_filter');
 add_action('wp_list_categories', 'art_vmenu_wp_list_categories_filter');

 /* Start demo Category add line */
 $exclude = demo_get_categoryID('slideshow');
 if ($exclude){
 wp_list_categories('title_li=&exclude='.$exclude.'');
 }else{
 wp_list_categories('title_li=');
 }
 /* End demo Category add line */
 remove_action('wp_list_categories', 'art_vmenu_wp_list_categories_filter');
 remove_action('get_terms', 'art_vmenu_get_terms_filter');

last step is to add our image into two Artisteer files, index.php and archive.php, look for this line and insert the code below.

Find: <?php while (have_posts()) : the_post(); ?> and paste in the following lines

&lt;!-- Start Check if our post is a slideshow post --&gt;
&lt;?php $slideCat = demo_get_categoryID('slideshow'); ?&gt;
&lt;?php if (in_category($slideCat) ) continue; ?&gt;
&lt;!-- End Check if our post is a slideshow post continue if it is --&gt;

So your code block should look like this:

&lt;?php while (have_posts()) : the_post(); ?&gt;

&lt;!-- Start Check if our post is a slideshow post --&gt;
&lt;?php $slideCat = demo_get_categoryID('slideshow'); ?&gt;
&lt;?php if (in_category($slideCat) ) continue; ?&gt;
&lt;!-- End Check if our post is a slideshow post continue if it is--&gt;
&lt;div&gt;

Now we have hidden our slideshow category from view, remember that this will hide all posts in the specified named category, so only add the category to posts you do not want displayed .

Notice

Code disclaimer information
This document contains programming examples therefore, www.DigitalRaindrops.net grants you a nonexclusive copyright license to use all programming code examples from which you can generate similar function tailored to your own specific needs.

All sample code is provided by www.DigitalRaindrops.net for learning illustrative purposes only.

These examples have not been thoroughly tested under all conditions. www.DigitalRaindrops.net, therefore, cannot guarantee or imply reliability, serviceability, or function of these examples.

All programs contained herein are provided to you “AS IS” without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Membership

We hope you will benefit from our tutorials Membership to this website is not required, however the downloading of any themes or files is restricted to site supporters.

You can register for a 10 year ‘Free Account’ from the members page which will give you access to the source files and free themes, as we introduce premium themes and content these will only be downloadable with a subscription, any revenue from subscriptions is used to support the site costs.

this website is a tool to support and promote WordPress and Artisteer, please support, share and give credit for any benefits you gain from the tutorials on this website.

2 thoughts on “Hiding a Single Category

  1. Pingback: Adding the cu3er Slideshow

  2. “Here air jordan 21 products xx, has fashion model, superior quality and service, cheap price and updates quickly.I support strongly always! I want to buy XX, I hesitate to select which style more better.Hope your unique recommends.

Leave a Reply

Connections

Connect with Us
Follow Digital Raindrops on Twitter Join Digital Raindrops on Facebook
Share

Related Posts

Posted in Tips

colorizer-1_thumb.png

We thought we would use the WordPress Twenty Eleven theme and the the Farbtastic color picker to colorize our theme from the website front page instead of the admin area. We have been looking at the $_SESSION variable,¬†so we thought … Continue reading

Read More