术语为空时隐藏分类

时间:2017-09-18 作者:Ali chashnigir

下面是我的代码,我想将其更改为在术语为空时隐藏分类法:

                <ul class="info-list">
                    <li>
                        <label><?php echo esc_html__( \'Actor:\', \'amy-movie\' ); ?></label>
                        <span><?php echo amy_movie_get_movie_taxomony( $post->ID, \'amy_actor\' ); ?></span>
                    </li>
                    <li>
                        <label><?php echo esc_html__( \'Director:\', \'amy-movie\' ); ?></label>
                        <span><?php echo amy_movie_get_movie_taxomony( $post->ID, \'amy_director\' ); ?></span>
                    </li>
                        <label><?php echo esc_html__( \'Genre:\', \'amy-movie\' ); ?></label>
                        <span><?php echo amy_movie_get_movie_taxomony( $post->ID, \'amy_genre\' ); ?></span>
                    </li>
                    <li>
                        <label><?php echo esc_html__( \'Release:\', \'amy-movie\' ); ?></label>
                        <span><?php echo esc_attr( date( get_option( \'date_format\' ), strtotime( $mdetails[\'movie_release\'] ) ) ); ?></span>
                    </li>
                    <li>
                        <label><?php echo esc_html__( \'Language:\', \'amy-movie\' ); ?></label>
                        <span><?php echo esc_attr( $mdetails[\'movie_language\'] ); ?></span>
                    </li>
                    <?php if ( amy_get_option( \'enable_m_cinema\', true ) == true ) : ?>
                    <li>
                        <label><?php echo esc_html__( \'Cinema:\', \'amy-movie\' ); ?></label>
                        <?php
                        if ( ! empty( $cinemas ) ) {
                            $numItems   = count( $cinemas );
                            $i          = 0;

                            foreach ( $cinemas as $cinema ) {
                                if ( ++$i === $numItems ) {
                                    $space = \'\';
                                } else {
                                    $space = \', \';
                                }

                                ?>
                                <a href="<?php echo get_permalink( $cinema ); ?>"><?php echo get_the_title( $cinema ); ?></a>
                                <?php echo esc_attr( $space ); ?>
                            <?php
                            }
                        }
                        ?>
                    </li>
                    <?php endif; ?>
                </ul> 

1 个回复
SO网友:Jan Boddez

许多自动主题正是针对标准标记和类别这样做的,也强调了初学者主题。直接从GitHub上的源代码开始:

$categories_list = get_the_category_list( esc_html__( \', \', \'_s\' ) );
if ( $categories_list ) {
    /* translators: 1: list of categories. */
    printf( \'\' . esc_html__( \'Posted in %1$s\', \'_s\' ) . \'\', $categories_list ); // WPCS: XSS OK.
}
根据分类法的需要进行调整。

结束

相关推荐