Wordpress投资组合:仅显示子类别

时间:2017-04-19 18:17:00

标签: php jquery wordpress

我有一个WP网站,其中包含投资组合部分。 在投资组合页面上显示项目类别。 我想只显示id = 63的父类别的子类别。

这是当前的代码:

    <?php $terms = get_the_terms( $post->ID , 'portfolio_category', 'string' ); ?>
    <?php $num_of_terms = count($terms); ?>

            <?php if($terms) { ?>   
            <div class="meta-column">
                    <strong class="caps"><?php esc_html_e( 'Artist', 'onioneye' ); ?><span class="colon">:</span></strong>
                    <span>
                        <?php 
                            $i = 0;

                            foreach($terms as $term) {

                                if($i + 1 == $num_of_terms) {
                                    echo esc_html($term -> name);
                                }
                                else {
                                    echo esc_html($term -> name . ', ');
                                }

                                $i++;
                            }
                        ?>
                    </span>
                </div>

            <?php } ?>

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

$args = array('child_of' => 63);
$terms = get_categories( $args );

取代这个:

$terms = get_the_terms( $post->ID , 'portfolio_category', 'string' );
相关问题