WordPress文章页面如何调用摘要?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了WordPress文章页面如何调用摘要?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1795字,纯文字阅读大概需要3分钟。
内容图文
![WordPress文章页面如何调用摘要?](/upload/InfoBanner/zyjiaocheng/236/ca009c4e032f4a16a3f3f16800572675.jpg)
回复内容:
给自己网站添加了360智能摘要,便于收录,其中有一行,需要在文章页的head标签中调用文章摘要,自己采用了get_the_excerpt和get_the_content函数都不行。不知该如何处理?
/**
* Custom Post Excerpt
*/
function wn_get_the_title($limit) {
global $post;
$title = sysSubStr( get_the_title(), $limit, true );
return $title;
}
function wn_get_the_excerpt($limit) {
global $post;
$excerpt = sysSubStr( get_the_excerpt(), $limit, true );
return $excerpt;
}
function wn_get_the_content($limit) {
global $post;
$content = sysSubStr( get_the_content(), $limit, true );
return $content;
}
// set the excerpt length
function custom_excerpt_length(){
return 250;
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
// set the excerpt more text
function custom_excerpt_more( $more ) {
return '……';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
function sysSubStr($string,$length,$append = false)
{
if(strlen($string) <= $length )
{
return $string;
}
else
{
$i = 0;
while ($i < $length)
{
$stringTMP = substr($string,$i,1);
if ( ord($stringTMP) >=224 )
{
$stringTMP = substr($string,$i,3);
$i = $i + 3;
}
elseif( ord($stringTMP) >=192 )
{
$stringTMP = substr($string,$i,2);
$i = $i + 2;
}
else
{
$i = $i + 1;
}
$stringLast[] = $stringTMP;
}
$stringLast = implode("",$stringLast);
if($append)
{
$stringLast .= "……";
}
return $stringLast;
}
}
function kankana_get_meta_description(){
$description = '';
$length = 100;
//if on home page
if(is_home() || is_front_page()){
$description = get_bloginfo( 'description' );
}elseif(is_singular()){
//if viewing a post/page
global $post;
$striped_content = wp_strip_all_tags( remove_all_shortcodes($post->post_content), true);
$description = mb_substr( $striped_content, 0, $length );
}
//elseif(is_archive())
return $description;
}
usage
内容总结
以上是互联网集市为您收集整理的WordPress文章页面如何调用摘要?全部内容,希望文章能够帮你解决WordPress文章页面如何调用摘要?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。