WordPress twentytwelve主题显示文章摘要,摘要字数设置

WordPress自带的主题twentytwelve默认首页是显示文章全文,一直想到要替换成显示文章摘要的形式,找了好多方法终于成功了。

方法:编辑主题文件 content.php ,找到is_search(),后面会有批注:// Only display Excerpts for Search,添加is_category() || is_archive() || is_home()判断条件,在这些情况下都显示摘要,只有查看文章时才全部显示。修改后为<?php if ( is_search() || is_category() || is_archive() || is_home()) : // Only display Excerpts for Search category archive home?>

WordPress默认的文章摘要字数是55,感觉显示太少了,所以要更改摘要的字数,网上有说的修改wp-includes文件夹里的formatting.php文件,可是这样一升级程序有恢复原设置了,所以推荐使用修改模板函数 文件functions.php,配合子主题使用,即使程序,主题升级之后,这些设置都能很好的保留。

e.g. 在主题的 /站点文件夹/wp-content/themes/twentytwelve/functions.php 结尾?>之前添加

function my_excerpt_length($length) { return 300; } add_filter(‘excerpt_length’, ‘my_excerpt_length’);

代码,300为文章摘要显示的字数,这样就把文章摘要字数设置为需要的字数了。

注意更新页脚备案信息:

在footer.php中:
1. 找到<div class="site-info" >,在其后加上 style=”text-align:center;”
2. 将wordpress.org的跳转改为:https://beian.miit.gov.cn/
3. 打印改为:printf( __( '京ICP备20015909号-1', 'twentytwelve' ), 'WordPress' );
4.链接改为:

<a href="<?php echo esc_url( __( 'https://beian.miit.gov.cn/', 'twentytwelve' ) ); ?>" class="imprint" target="_blank" title="<?php esc_attr_e( '你在闲逛', 'twentytwelve' ); ?>">

原文:http://wangqingzi.com/wordpress-twentytwelve-zhaiyao.html

发表评论

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