首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在类别页面模板中列出类别的子类别(wordpress)

如何在类别页面模板中列出类别的子类别(wordpress)
EN

Stack Overflow用户
提问于 2014-10-31 04:14:16
回答 1查看 676关注 0票数 0

我有一个类别页面模板,列出了所有类别的特色图像。但我只想显示父类别的子类别。我不知道在哪里修改模板。下面是代码。

代码语言:javascript
复制
get_header(); ?>

<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>

    <h1 class="border-radius-5"><?php the_title(); ?></h1>

        <div id="page" class="post-content">

            <?php the_content(); ?>

            <?php
                $terms = get_terms("category", $args);
                $count = count($terms);
                $categories = array();

                if ($count > 0) {

                echo '<ul class="listing-cat">';

                foreach ($terms as $term) {

                $args = array(
                    'post_type'        => 'post',
                    'posts_per_page'   => 1,
                    'show_count'       => 1,
                    'orderby'          => 'rand',
                    'post_status'      => 'publish',
                    'tax_query' => array(
                                        array(
                                            'taxonomy' => 'category',
                                            'field' => 'slug',
                                            'terms' => $term->slug
                                        )
                                    )
                );

                $video_from_categorie = new WP_Query( $args );

                if( $video_from_categorie->have_posts() ){

                    $video_from_categorie->the_post();

                }else{}

                $term->slug;
                $term->name;

            ?>

        <li class="border-radius-5 box-shadow">
            <?php echo get_post_image();?>

            <a href="<?php echo get_category_link( get_cat_ID($term->name) ); ?>" title="<?php echo $term->name; ?>"><span><?php echo $term->name; ?></span></a> 

            <span class="nb_cat border-radius-5"><?php echo $term->count; ?> <?php if ( $term->count > 1 ){
                _e( 'videos', get_theme_name() );
            }else{
                _e( 'video', get_theme_name() );
            } ?></span>                   
        </li>

    <?php
        }
        echo '</ul>';
        echo '<div class="clear"></div>';
        }
    ?>

    </div><!-- #page --> 

<?php endwhile; ?>

<?php endif; ?>
EN

回答 1

Stack Overflow用户

发布于 2014-10-31 04:56:06

将所需父术语/类别的ID传递给get_terms()child_of参数

代码语言:javascript
复制
$terms = get_terms( 'category', array( 'child_of' => TERM_ID_GOES_HERE ) );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26662446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档