我试图从基于函数的类别列表中排除类别。我在这里浏览和研究了很多,但找不到解决方案。下面是我在侧边栏中使用的代码:
<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>
我想排除几个类别,所以我使用了以下代码:
<?php wp_list_categories(\'exclude=4,7&title_li=\'); ?>
结果:类别确实被排除,但功能不再正常工作。
该函数应拉出每个类别的屏幕盖以显示。一旦我排除了类别,屏幕截图就不再显示了。
以下是功能代码:
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;
}
}
}
}
你知道我如何修改代码以排除类别而不破坏函数的功能吗?
提前多谢!
最合适的回答,由SO网友:s_ha_dum 整理而成
这
<?php wp_list_categories(\'exclude=4,7&title_li=\'); ?>
。。。不包括您的助行器。你为什么不加上
exclude
和你添加其他人的方式一样?
$args = array();
$args[\'show_last_updated\'] = true;
$args[\'show_count\'] = true;
$args[\'title_li\'] = \'\';
$args[\'exclude\'] = \'4,7\';
$args[\'walker\'] = new CategoryThumbnail_Walker;
wp_list_categories($args);