阅读背景:

wordpress百度熊掌号“搜索结果出图”改造代码

来源:互联网 
<?php
if(is_single()||is_page()){
	echo '<script type="application/ld+json">{
	"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
	"@id": "'.get_the_permalink().'",
 	"appid": "这里请填写熊掌号 ID",
	"title": "'.get_the_title().'",
	"images": ["'.fanly_post_imgs().'"],
	"pubDate": "'.get_the_time('Y-m-d\TH:i:s').'"
}</script>
';}
//获取文章中的图 last update 2018/01/22
function fanly_post_imgs(){
	global $post;
	$src = '';
	$content = $post->post_content;  
	preg_match_all('/<img .*?src=[\"|\'](.+?)[\"|\'].*?>/', $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;
}
?>
<?php
if(is_single()||is_page()){
	echo '<s



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: