WordPress:从我的内容模板中删除get_the_title

时间:2019-01-07 23:02:52

标签: php wordpress

我正在为我的客户网站运行_underscores主题的变体,并且我们已经在自定义标头元素中显示了页面或帖子标题,因此不再需要将其放在模板部分的循环中/content.php。我以为只删除'get_the_title'可以消除在帖子正文中看到标题的问题,但是,我只是遇到了各种错误,例如'unexpected')'或类似错误。那么,如何摆脱get_the_title参考,仍然使之有效?这是我目前的情况。

<div class="entry-content">
    <?php if ( is_category() || is_archive() ) {
        the_excerpt('');
            } else {
        the_content( sprintf(
        wp_kses(
            /* translators: %s: Name of current post. Only visible to screen readers */
            __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'orchestra' ),
            array(
                'span' => array(
                    'class' => array(),
                ),
            )
        ),
        get_the_title()
    ) );

    if ( is_category() || is_archive() ) {
        echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
    }

    wp_link_pages( array(
        'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
        'after'  => '</div>',
    ) );
    }
    ?>

1 个答案:

答案 0 :(得分:1)

对此的格式使其相对难以阅读。所以首先我要清理一下。如果查看the_content()的文档,您会看到第一个参数是$more_text_link。因此,第515行添加了“继续阅读[帖子标题]”测试。

如果您根本不需要它,可以像这样使用the_content()

<div class="entry-content">
    <?php
        if( is_category() || is_archive() ){
            the_excerpt('');
        } else {
            the_content();

            if( is_category() || is_archive() ){
                echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
            }

            wp_link_pages( array(
                'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
                'after'  => '</div>',
            ) );
        }
    ?>

否则,您需要添加自己的默认文本:

<div class="entry-content">
    <?php
        if( is_category() || is_archive() ){
            the_excerpt('');
        } else {
            the_content( 'Continue Reading' );

            if( is_category() || is_archive() ){
                echo '<p class="btn-cc"><a href="%s" rel="bookmark">Read More</a></p>';
            }

            wp_link_pages( array(
                'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'orchestra' ),
                'after'  => '</div>',
            ) );
        }
    ?>