【问题标题】:Adding category title to WordPress theme file将类别标题添加到 WordPress 主题文件
【发布时间】:2013-09-28 12:48:23
【问题描述】:

在我的自定义 WordPress 主题的 archives.php 文件中,我有以下代码:

<div class="page-title">
<?php
                if ( is_day() ) :
                    printf( __( 'Daily Archives: %s', 'sturd' ),     '<span>' . get_the_date() . '</span>' );
                elseif ( is_month() ) :
                    printf( __( 'Monthly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'sturd' ) ) . '</span>' );
                elseif ( is_year() ) :
                    printf( __( 'Yearly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'sturd' ) ) . '</span>' );
                else :
                    _e( 'Archives', 'sturd' );
                endif;
            ?>
</div>

我希望有另一个声明,这样如果这是一个类别页面,它只会在页面标题 div 中显示类别标题,而不仅仅是单词 Archives(就像现在一样)。

我希望这发布在正确的部分。

提前致谢。

山姆

【问题讨论】:

标签: php wordpress wordpress-theming


【解决方案1】:

首先,我建议您熟悉 WP template hierarchy。我通常建议使用单独的 category.php 模板文件来显示类别,并使用single_cat_title() 来显示类别名称。

如果要使用主archive.php 模板,可以添加is_category() 子句,然后使用single_cat_title() 获取名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 2016-10-09
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    相关资源
    最近更新 更多