2017情人节写代码到凌晨,成果如下,哈哈……

  • A+
所属分类:刘志强

2017情人节写代码到凌晨,成果如下,哈哈......
现在搜索引擎都搞结构化数据,没办法为了适应,用三小时写了如下代码:
<?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

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: