首頁 > 後端開發 > php教程 > WordPress 文章页面如何调用摘要?

WordPress 文章页面如何调用摘要?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-06 20:44:21
原創
1240 人瀏覽過

给自己网站添加了360智能摘要,便于收录,其中有一行,需要在文章页的head标签中调用文章摘要,自己采用了get_the_excerpt和get_the_content函数都不行。不知该如何处理?

<code><meta property="og:description" content="<?php get_the_excerpt();?>">
</code>
登入後複製
登入後複製

回复内容:

给自己网站添加了360智能摘要,便于收录,其中有一行,需要在文章页的head标签中调用文章摘要,自己采用了get_the_excerpt和get_the_content函数都不行。不知该如何处理?

<code><meta property="og:description" content="<?php get_the_excerpt();?>">
</code>
登入後複製
登入後複製

<code>/**
 * 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) =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; 
    } 
} 
</code>
登入後複製

<code>    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;

    }
</code>
登入後複製

usage

<code>  <meta property="og:description" content="<?php echo kankana_get_meta_description();?>">
</code>
登入後複製
相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
怎麼學好php
來自於 1970-01-01 08:00:00
0
0
0
PHP擴充intl
來自於 1970-01-01 08:00:00
0
0
0
php數據獲取?
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板