现在搜索引擎都搞结构化数据,没办法为了适应,用三小时写了如下代码:
<?php
require('./wp-blog-header.php');
$posts_to_show = 200;
echo '<?xml version="1.0" encoding="utf-8" ?> '; ?>
<document>
<webName><![CDATA[<?php bloginfo('name'); ?>]]></webName>
<?php echo '<hostName><![CDATA[www.weijiezm.net]]></hostName> '; ?>
<?php
header("Content-type: text/xml");
$myposts = get_posts( "numberposts=" . $posts_to_show );
function tagtext(){
global $post;
$gettags = get_the_tags();
if ($gettags) {
foreach ($gettags as $tag) {
$posttag[] = $tag->name;
}
$tags = implode( ',', $posttag );
echo $tags;
}
}
foreach( $myposts as $post ) { ?>
<datalist>
<item>
<url><![CDATA[<?php the_permalink(); ?>]]></url>
<title><![CDATA[<?php the_title(); ?>]]></title>
<publishDate><![CDATA[<?php the_time('c') ?>]]></publishDate>
<summary><![CDATA[<?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 100,"...",'utf-8'); ?>]]></summary>
<tags><![CDATA[<?php tagtext();?>]]></tags>
<img1><![CDATA[<?php $thumbnail_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail');echo $thumbnail_image_url[0]; ?>]]></img1>
<category><![CDATA[<?php the_category(’, ‘) ?>]]></category>
</item>
</datalist>
<?php } ?>
</document>
2017.2.14