繁体   English   中英

在Wordpress的自定义页面模板中显示分类法信息

[英]Show post taxonomy information in custom page template in wordpress

我有一个主题,我正在通过子主题进行编辑。 我已经能够创建自定义页面模板,因为我想使用自定义页面为特定帖子类型添加分类信息。

自定义页面具有以下代码

<div id="primary" class="content-area col-sm-12 col-md-8 <?php echo of_get_option( 'site_layout' ); ?>">
    <main id="main" class="site-main" role="main">

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

            <?php get_template_part( 'content', 'page' ); ?>

            <?php
                // If comments are open or we have at least one comment, load up the comment template
                if ( comments_open() || '0' != get_comments_number() ) :
                    comments_template();
                endif;
            ?>

        <?php endwhile; // end of the loop. ?>

    </main><!-- #main -->
</div><!-- #primary -->

我需要在每个描述下方添加分类法信息。 说职位类型的名称是食品,我该如何在上面添加代码以显示每个职位的分类法(创建,大小,时间,类型)信息。

根据帖子ID在while循环中为类别列表添加以下代码。

//Returns Array of Term for "my_taxonomy"
$terms = get_the_terms( get_the_ID(), 'my_taxonomy' );

if ( $terms && ! is_wp_error( $terms ) ) : 

    $terms_links = array();

    foreach ( $terms as $term ) {
        $terms_links[] = $term->name;
    }

    $on_terms = join( ", ", $terms_links );
    ?>

    <p>
        <?php printf( esc_html__( 'Categories : <span>%s</span>', 'textdomain' ), esc_html( $on_terms ) ); ?>
    </p>
<?php endif; ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM