Twenty Fifteen主题首页摘要显示方法
Twenty Fifteen主题首页摘要显示方法一
我们知道,在搜索结果中文章是以摘要的形式显示的,因此在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;
更改为以下代码。只是把content改为了content-search。
- <?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-search', get_post_format() );
- // End the loop.
- endwhile;
好了,刷新一下首页就可以看到结果了。
twentyfifteen主题首页摘要显示方法二
twentyfifteen首页摘要显示方法二是修改content.php文件。先看看content.php以下部分
- <div class="entry-content">
- <?php
- /* translators: %s: Name of current post */
- the_content( sprintf(
- __( 'Continue reading %s', 'twentyfifteen' ),
- the_title( '<span class="screen-reader-text">', '</span>', false )
- ) );
- wp_link_pages( array(
- 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>',
- 'after' => '</div>',
- 'link_before' => '<span>',
- 'link_after' => '</span>',
- 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%',
- 'separator' => '<span class="screen-reader-text">, </span>',
- ) );
- ?>
- </div><!-- .entry-content-–>
修改成以下代码形式,也就是说除了文章内页以外,全部以摘要的方法显示。
- <div class="entry-content">
- <?php
- if ( is_single() ) :
- /* translators: %s: Name of current post */
- the_content( sprintf(
- __( 'Continue reading %s', 'twentyfifteen' ),
- the_title( '<span class="screen-reader-text">', '</span>', false )
- ) );
- wp_link_pages( array(
- 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>',
- 'after' => '</div>',
- 'link_before' => '<span>',
- 'link_after' => '</span>',
- 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%',
- 'separator' => '<span class="screen-reader-text">, </span>',
- ) );
- else :
- /* translators: %s: Name of current post */
- the_excerpt( sprintf(
- __( 'Continue reading %s', 'twentyfifteen' ),
- the_title( '<span class="screen-reader-text">', '</span>', false )
- ) );
- wp_link_pages( array(
- 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>',
- 'after' => '</div>',
- 'link_before' => '<span>',
- 'link_after' => '</span>',
- 'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%',
- 'separator' => '<span class="screen-reader-text">, </span>',
- ) );
- endif;
- ?>
- </div><!-- .entry-content-–>
twentyfifteen主题更改摘要字数
虽然经过上面的修改,twentyfifteen主题是以摘要的方法显示了,但是摘要字数并不满意,字数太少。我们可以通过修改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 );
标签: Twenty Fifteen WordPress主题
评论:
日历
分类
最新评论
- 鸟叔
拿走用了,感谢 - 雷达探币
旧时光是个哑巴,唱不... - lijiayan
@林林:是的~ - 雷达探币
妾似琵琶斜入抱,任君... - 林林
如果网站是使用htt... - 林林
能换个友情链接吗? ... - 马内
感谢博主的分享,支持... - aussiegabmbling
论坛过来看看博主 - aussie_gabmbling
關於這個主題的好網站 - 大卖家
很好啊,顶一下
热门日志
随机日志
存档
- 2021年12月(1)
- 2021年11月(1)
- 2021年10月(1)
- 2021年8月(2)
- 2021年7月(1)
- 2021年6月(1)
- 2021年5月(1)
- 2021年4月(2)
- 2019年12月(1)
- 2019年5月(1)
- 2018年12月(1)
- 2018年9月(2)
- 2018年7月(2)
- 2018年6月(2)
- 2018年5月(1)
- 2018年4月(2)
- 2018年3月(2)
- 2018年2月(5)
- 2017年9月(1)
- 2017年8月(1)
- 2017年4月(1)
- 2016年12月(5)
- 2016年8月(2)
- 2016年3月(2)
- 2016年1月(1)
- 2015年11月(1)
- 2015年9月(2)
- 2015年8月(2)
- 2015年6月(2)
- 2015年5月(2)
- 2015年4月(2)
- 2015年3月(2)
- 2015年1月(1)
- 2014年11月(6)
- 2014年10月(2)
- 2014年9月(2)
- 2014年8月(6)
- 2014年7月(3)
- 2014年6月(10)
- 2014年5月(3)
- 2014年4月(2)
- 2014年3月(9)
- 2014年1月(1)
- 2013年12月(9)
- 2013年11月(11)
- 2013年10月(7)
- 2013年9月(18)
- 2013年8月(8)
- 2013年7月(15)
- 2013年6月(17)
- 2013年5月(17)
- 2013年4月(10)
- 2013年3月(17)
- 2013年2月(20)
- 2013年1月(37)
- 2012年12月(12)
- 2008年12月(1)
2021-11-07 12:39