...

View Full Version : Exclude category names



swedy13
01-14-2012, 02:12 AM
Hello, I'm trying to alter my site code to only retrieve certain categories. Specifically, I want to exclude a few category names from the basic retrieval code. Here is the code I currently have:


<!-- Begin #colRight -->
<div id="colRight">
<?php
if(get_option('boldy_blog')!='' && is_category(get_option('boldy_blog')) || post_is_in_descendant_category( get_option('boldy_blog'))){
$current = get_the_category();
if(sizeof($current)>0){
$current_id= $current[0] ->cat_ID;
$categs_list = get_category_parents($current_id);
$pieces = explode("/", $categs_list);
$category_name = strtolower($pieces[0]);
$categs = get_cat_id($category_name);
?>
<div class="rightBox">
<h2><?php echo get_cat_name(get_option('boldy_blog'));?> Categories </h2>
<ul >
<?php
$categories = get_categories('hide_empty=1&child_of='.$categs);
foreach ($categories as $cat) {
echo ('<li><a href="');
echo (get_category_link($cat->cat_ID).'">'.$cat->cat_name.'</a></li>');
}?>
</ul>
</div>
<?php }}?>

<?php /* Widgetized sidebar */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>

</div>
<!-- End #colRight -->


Some of the categories I want to remove are called:

Around the Web
Guides
Reflections
Interviews


Thanks for the help!

mlseim
01-14-2012, 02:44 AM
Is it WordPress?

swedy13
01-14-2012, 02:45 AM
Yes, a Wordpress blog on my own site.

swedy13
01-14-2012, 02:53 AM
Here is a link to my site (http://www.zoiology.com/category/blog/) if that helps. I'm trying to change the sidebar feature called "Blog Topics"

mlseim
01-14-2012, 05:32 PM
I'm just sort of taking a stab at this one. Make a safe copy of your current script
before overwriting it. I'm thinking that instead of "get_categories", you will use
"list_categories" and specify the one's you want.

You currently are using the permalink (without an id number), but your categories
still have id numbers associated with them. View your categories in your admin and
note the id numbers for each one. You'll see in my example, I just put random
category numbers there ... switch those with the ones you want to appear in
your sidebar list.




<div class="rightBox">
<h2><?php echo get_cat_name(get_option('boldy_blog'));?> Categories </h2>
<ul >
<?wp_list_categories('include=12,5,8,10,3,4&title_li=');?>
</ul>
</div>



Here are the types of things you'll be using online for information .. WP CODEX

http://codex.wordpress.org/Template_Tags/wp_list_categories#Include_or_Exclude_Categories
http://codex.wordpress.org/Function_Reference/get_categories

Use the CODEX website for all of your specific customization needs:
http://codex.wordpress.org/Main_Page



.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum