twentyfifteen主题首页摘要显示方法

在主题文件夹下的index.php文件中找到如下代码:

            <?php
            // Start the loop.
            while ( have_posts() ) : the_post();

                /*
                 * Include the Post-Format-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                 */
                get_template_part( 'content', get_post_format() );

            // End the loop.
            endwhile;

将get_template_part( ‘content’, get_post_format() )中的content改为content-search,保存好再次刷新网站就可以看到文章是以摘要形式显示了

更改摘要显示字数

在functions.php找到如下代码:

function twentyfifteen_search_form_modify( $html ) {
    return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
}
add_filter( 'get_search_form', 'twentyfifteen_search_form_modify' );

在后面加上以下代码(200表示摘要显示的字数)

function twenty_fifteen_excerpt_length( $length ) {
return 200;
}
add_filter( 'excerpt_length', 'twenty_fifteen_excerpt_length', 999 );

已发布

分类

来自

标签:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注