【发布时间】:2014-01-28 13:42:32
【问题描述】:
我想知道如何仅显示父类别的子类别?
有什么办法吗?
我正在使用此代码。
<?php
if (is_category())
{
$cur_cat = get_query_var('cat');
if ($cur_cat)
{
$new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat .'&depth=1&title_li=&&show_count=1&hide_empty=0');
echo '<ul>' . $new_cats . '</ul>';
}
}
?>
我有父类别视频和 3 个艺术、技术和有趣的子类别。
现在我只想在category:videos 中显示 3 个子类别
但我的问题是还有显示父类别的帖子。当我转到任何子类别页面时,类别标题上会显示此行No categories。
例如,当我进入艺术分类页面时,在Art的分类标题上会显示这一行。
请建议我完整且有用的解决方案。
更新
这是我的整个category.php 模板:
<?php get_header(); ?>
<article class="content">
<div id="marquee-container"><div title="News Updates…" alt="News Updates…" style="position:relative; background-color: #FFF; width:137px; height:19px; z-index:1; border-radius:3px; background-image:url(<?php bloginfo('template_directory'); ?>/images/wp0465f11b_06.png); display:inline-block;"></div><h4 class="marquee-text">New Features Coming Soon...</h4></div>
<?php if ( have_posts() ) : ?>
<div class="posts">
<h1 class="archive-title"><?php printf( __( 'Category: %s', 'OnlinEarn' ), single_cat_title( '', false ) ); ?></h1>
<?php if ( category_description() ) : // Show an optional category description ?>
<div class="archive-meta"><?php echo category_description(); ?></div>
<?php endif; ?>
<?php $args = array('child_of' => 'videos'); ?>
<?php
if (is_category('videos'))
{
$cur_cat = get_query_var('cat');
if ($cur_cat)
{
$new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat .'&depth=1&title_li=&&show_count=1&hide_empty=0');
}
}
?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="block"><?php get_template_part( 'content', get_post_format() ); ?></div>
<?php endwhile; ?>
</div><!--.posts-->
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</article><!-- .content -->
【问题讨论】:
-
有人会回答我的问题吗?我深受其害。