熊掌号php对接,WordPress接入熊掌号及页面改造

编程入门 行业动态 更新时间:2024-10-14 08:26:42

<a href=https://www.elefans.com/category/jswz/34/1744734.html style=熊掌号php对接,WordPress接入熊掌号及页面改造"/>

熊掌号php对接,WordPress接入熊掌号及页面改造

WordPress主题改造文件有所不同,这里我当前使用知更鸟Lts版本,需用到的3个文件分别为functions.php、head.php、content.php。

添加熊掌号ID声明

首先使用到的是head.php,添加熊掌号ID声明,代码如下:

添加JSON_LD数据"application/ld+json">

{

"@context": ".jsonld",

"@id": "",

"appid": "熊掌号ID",

"title": "",

"images": ["'.fanly_post_imgs().'"],

"description": "",

"pubDate": ""

}

functions.php添加//获取文章/页面摘要

function fanly_excerpt($len=220){

if ( is_single() || is_page() ){

global $post;

if ($post->post_excerpt) {

$excerpt = $post->post_excerpt;

} else {

if(preg_match('/

(.*)/iU',trim(strip_tags($post->post_content,"

")),$result)){ $post_content = $result['1']; } else { $post_content_r = explode("\n",trim(strip_tags($post->post_content))); $post_content = $post_content_r['0']; } $excerpt = preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s','$1',$post_content); } return str_replace(array("\r\n", "\r", "\n"), "", $excerpt); } }//获取文章中的图

function fanly_post_imgs(){

global $post;

$src = '';

$content = $post->post_content;

preg_match_all('//', $content, $strResult, PREG_PATTERN_ORDER);

$n = count($strResult[1]);

if($n >= 3){

$src = $strResult[1][0].'","'.$strResult[1][1].'","'.$strResult[1][2];

}elseif($n >= 1){

$src = $strResult[1][0];

}

return $src;

}

content.php添加

以下代码不同主题可能有所不同,根据实际情况添加适当位置,本站当前在105行处添加,文件目录为主题目录/template/content.php

效果展示:

更多推荐

熊掌号php对接,WordPress接入熊掌号及页面改造

本文发布于:2024-03-11 15:46:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1729315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:熊掌   页面   php   WordPress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!