I'm trying to exclude categories from a function-based category list. I browsed and researched here a lot, but couldn't find a solution. Here's the code I use in my sidebar:
<ul class="side-cat-img"> <li>
<?php $args = array();
$args['show_last_updated'] = true;
$args['show_count'] = true;
$args['title_li'] = '';
$args['walker'] = new CategoryThumbnail_Walker;
wp_list_categories($args); ?>
</li>
</ul>
I want to exclude a few categories, so I used this code:
<?php wp_list_categories('exclude=4,7&title_li='); ?>
Result: The categories were really excluded, but the function didn't work properly anymore.
The function is supposed to pull out a screencap of each category to display. Once I excluded categories, the screenshots didn't show up anymore.
Here's the function code:
class CategoryThumbnail_Walker extends Walker_Category {
// A new element has been stumbled upon and has ended
function end_el( &$output, $category, $depth, $args ) {
// Output the standard link ending
parent::end_el( &$output, $category, $depth, $args );
// Get one post
$posts = get_posts( array(
// ...from this category
'category' => $category->cat_ID,
'numberposts' => 10
) );
// we'll record the seen images here
if ( !isset($this->images_seen) ) $this->images_seen = array();
foreach ( $posts as $post ) {
// Get its thumbnail and append it to the output
$featured = get_the_post_thumbnail( $post->ID, 'latestpost-thumb', null );
// have we already seen this image?
if ( in_array($featured, $this->images_seen) ) continue;
else {
$this->images_seen []= $featured;
$post_cats = get_the_category($post->ID);
$output .= '<li><a href="http://zoomingjapan.com/category/'.$post_cats[0]->slug.'" title="Category Name">'.$featured.'</a></li>';
break;
}
}
}
}
Any ideas how I can change the code to exclude categories without destroying what the function is supposed to do?
Thanks a lot in advance!