簡體   English   中英

如何只顯示在WordPress的父類別頁面中的子類別?

[英]how to show only subcategories in parent category page in wordpress?

我想知道如何僅顯示父類別中的子類別?

有什么辦法嗎?

我正在使用此代碼。

<?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個子category:videos

但是我的問題是,也顯示了父類別的帖子。 當我轉到任何子類別頁面時,在類別標題上都顯示此行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 -->
<?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; endif;

            $category = get_the_category();

            if ($category[0]->category_parent != '' && is_category('video')) :

             //show child categories
            $cur_cat = get_query_var('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>';

            elseif ( have_posts() ) : 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 -->

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM