<?php
function my_more_link($link){
//制止more标签主动跳转
$link=preg_replace('/#more-\d+/i','',$link);
//我在more标签的核心加了一层 p, 用以更不便地自定义more标签在页面中的显示(应用 p.read-more)
$link=str_replace('<a','<p class="read-more"><a rel="nofollow" title="持续浏览: '.get_the_title($post->post_title).'"',$link);
//闭合新包裹的 p
$link=str_replace('</a>','</a></p>',$link);
return $link;
}
add_filter('the_content_more_link','my_more_link');//把函数追退出主题
?>
<?php //这是为了在单篇文章(或页面)间接显示全副内容,而不应用以下的判别
if(is_singular()){the_content();}else{
//定义两个$
$pc=$post->post_content;
$st=strip_tags(apply_filters('the_content',$pc));
//判别能否存在 内置摘要
if(has_excerpt())
the_excerpt();
/*应用正则表白式尝试婚配more标签,
并判别假如存在more标签, 或许注释内容长度小于300, 则间接以more标签形式显示,
即是说, 有more便显示more, 没more且长度小于300则间接显示全文.
我应用了mb_strwidth来判别长度.
*/
elseif(preg_match('/<!--more.*?-->/',$pc) || mb_strwidth($st)<300)
the_content('Read more »');
//否则...以下
elseif(function_exists('mb_strimwidth'))//判别能否支持mb_strimwidth函数
echo'<p>'//mb_strimwidth截断后失去的是纯文本, 所以我给它包了一层 p
.mb_strimwidth($st,0,300,' ...')//对文本内容截断, 从地位0开端往后截取300长度, 超出局部以点点点代替
.'</p><p class="read-more"><a title="'//给截断的内容增加一个与 STEP 1 齐全如出一辙的"more标签"...
.the_title("持续浏览: ","",false)//留意这里与 STEP 1 相比, 应用了另一个函数来获取题目
.'" rel="nofollow" href="'
.post_permalink()
.'" class="more-link">Read more »</a></p>';
else the_content();//最初没有抉择的抉择...
}?>
以上就是安达网络工作室关于《较**的WordPress文章摘要(截断)方案分享》的一些看法。更多内容请查看本栏目更多内容!
1.增加性能 在function.php中拔出代码 add_theme_support('post-thumbnails'); 拔出之后会在后盾编辑文章的...
复制代码代码如下:add_filter( 'wp_handle_upload_prefilter', 'custom_upload_name' ); function custom...
WordPress网站在改换域名后,需求从新配置以后域名能力使得网站失常运转,很多人遇到过这样的状况,那么如何...
Tiobe Index(编程言语世界排名指数),是一个显示各种编程言语的绝对盛行趋向的排名,开端于 2001 年,每...
共性化登陆界面的办法有两种,第一种是交换登陆背景,这个算是小型共性化吧: 在/wp-admin/images找到login...
1. Wordpress的明码在存入数据库是以md5码的方式寄存 依据此原理能够手动update数据库,从新设置自定的明码 ...