WordPress纯代码生成XML和HTML站点地图

2018年5月23日17:55:50 发表评论 527 人围观

网站地图,一般放置在网站的底部。又分为XML地图和HTML地图,XML主要是方便搜索引擎的收录。HTML是给人看的。

WordPress纯代码生成XML和HTML站点地图

网站地图生成可以使用插件来实现,也可以使用纯代码。新手站长可以使用插件来直接生成,简单方便快捷。如果不想用插件,觉得会拖慢网站速度,可以使用纯代码来实现。

 

纯代码生成XML地图

插件会拖慢运行速度,大家都是弄网站的,都喜欢自己动手,很有成就感。大部分站长都喜欢纯代码实现功能。

新建PHP文件xmlmap.php,将如下代码复制进去,上传的网站根目录。然后打开你的网站域名/xmlmap.php就能看到了。

<span class="pun"><?</span><span class="pln">php
</span><span class="kwd">require</span><span class="pun">(</span><span class="str">'./wp-blog-header.php'</span><span class="pun">);</span><span class="pln">
header</span><span class="pun">(</span><span class="str">"Content-type: text/xml"</span><span class="pun">);</span><span class="pln">
header</span><span class="pun">(</span><span class="str">'HTTP/1.1 200 OK'</span><span class="pun">);</span><span class="pln">
$posts_to_show </span><span class="pun">=</span> <span class="lit">1000</span><span class="pun">;</span><span class="pln">
echo </span><span class="str">'<?xml version="1.0" encoding="UTF-8"</span><span class="pun">?></span><span class="pln">';
echo '</span><span class="tag"><urlset</span> <span class="atn">xmlns</span><span class="pun">=</span><span class="atv">"http://www.<a href="http://www.ooomg.cn/tag/sitemap" title="查看与 sitemap 相关的文章" target="_blank">sitemap</a>s.org/schemas/<a href="http://www.ooomg.cn/tag/sitemap" title="查看与 sitemap 相关的文章" target="_blank">sitemap</a>/0.9"</span> <span class="atn">xmlns:mobile</span><span class="pun">=</span><span class="atv">"http://www.baidu.com/schemas/sitemap-mobile/1/"</span><span class="tag">></span><span class="pln">'
</span><span class="pun">?></span>
<span class="com"><!-- generated-on=<?php echo get_lastpostdate('blog'); ?> Diy By 余斗--></span>
<span class="tag"><url></span>
<span class="tag"><loc></span><span class="pun"><?</span><span class="pln">php echo get_home_url</span><span class="pun">();</span> <span class="pun">?></span><span class="tag"></loc></span>
<span class="tag"><lastmod></span><span class="pun"><?</span><span class="pln">php $ltime </span><span class="pun">=</span><span class="pln"> get_lastpostmodified</span><span class="pun">(</span><span class="pln">GMT</span><span class="pun">);</span><span class="pln">$ltime </span><span class="pun">=</span><span class="pln"> gmdate</span><span class="pun">(</span><span class="str">'Y-m-d\TH:i:s+00:00'</span><span class="pun">,</span><span class="pln"> strtotime</span><span class="pun">(</span><span class="pln">$ltime</span><span class="pun">));</span><span class="pln"> echo $ltime</span><span class="pun">;</span> <span class="pun">?></span><span class="tag"></lastmod></span>
<span class="tag"><changefreq></span><span class="pln">daily</span><span class="tag"></changefreq></span>
<span class="tag"><priority></span><span class="pln">1.0</span><span class="tag"></priority></span>
<span class="tag"></url></span>
<span class="pun"><?</span><span class="pln">php
</span><span class="com">/* 文章页面 */</span><span class="pln">
header</span><span class="pun">(</span><span class="str">"Content-type: text/xml"</span><span class="pun">);</span><span class="pln">
$myposts </span><span class="pun">=</span><span class="pln"> get_posts</span><span class="pun">(</span> <span class="str">"numberposts="</span> <span class="pun">.</span><span class="pln"> $posts_to_show </span><span class="pun">);</span>
<span class="kwd">foreach</span><span class="pun">(</span><span class="pln"> $myposts </span><span class="kwd">as</span><span class="pln"> $post </span><span class="pun">)</span> <span class="pun">{</span> <span class="pun">?></span>
<span class="tag"><url></span>
<span class="tag"><loc></span><span class="pun"><?</span><span class="pln">php the_permalink</span><span class="pun">();</span> <span class="pun">?></span><span class="tag"></loc></span>
<span class="tag"><lastmod></span><span class="pun"><?</span><span class="pln">php the_time</span><span class="pun">(</span><span class="str">'c'</span><span class="pun">)</span> <span class="pun">?></span><span class="tag"></lastmod></span>
<span class="tag"><changefreq></span><span class="pln">monthly</span><span class="tag"></changefreq></span>
<span class="tag"><priority></span><span class="pln">0.6</span><span class="tag"></priority></span>
<span class="tag"></url></span>
<span class="pun"><?</span><span class="pln">php </span><span class="pun">}</span> <span class="com">/* 文章循环结束 */</span> <span class="pun">?></span>
<span class="pun"><?</span><span class="pln">php
</span><span class="com">/* 单页面 */</span><span class="pln">
$mypages </span><span class="pun">=</span><span class="pln"> get_pages</span><span class="pun">();</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">count</span><span class="pun">(</span><span class="pln">$mypages</span><span class="pun">)</span> <span class="pun">></span> <span class="lit">0</span><span class="pun">)</span> <span class="pun">{</span>
<span class="kwd">foreach</span><span class="pun">(</span><span class="pln">$mypages </span><span class="kwd">as</span><span class="pln"> $page</span><span class="pun">)</span> <span class="pun">{</span> <span class="pun">?></span>
<span class="tag"><url></span>
<span class="tag"><loc></span><span class="pun"><?</span><span class="pln">php echo get_page_link</span><span class="pun">(</span><span class="pln">$page</span><span class="pun">-></span><span class="pln">ID</span><span class="pun">);</span> <span class="pun">?></span><span class="tag"></loc></span>
<span class="tag"><lastmod></span><span class="pun"><?</span><span class="pln">php echo str_replace</span><span class="pun">(</span><span class="str">" "</span><span class="pun">,</span><span class="str">"T"</span><span class="pun">,</span><span class="pln">get_page</span><span class="pun">(</span><span class="pln">$page</span><span class="pun">-></span><span class="pln">ID</span><span class="pun">)-></span><span class="pln">post_modified</span><span class="pun">);</span> <span class="pun">?></span><span class="tag"></lastmod></span>
<span class="tag"><changefreq></span><span class="pln">weekly</span><span class="tag"></changefreq></span>
<span class="tag"><priority></span><span class="pln">0.6</span><span class="tag"></priority></span>
<span class="tag"></url></span>
<span class="pun"><?</span><span class="pln">php </span><span class="pun">}}</span> <span class="com">/* 单页面循环结束 */</span> <span class="pun">?></span>
<span class="pun"><?</span><span class="pln">php
</span><span class="com">/* 博客分类 */</span><span class="pln">
$terms </span><span class="pun">=</span><span class="pln"> get_terms</span><span class="pun">(</span><span class="str">'category'</span><span class="pun">,</span> <span class="str">'orderby=name&hide_empty=0'</span> <span class="pun">);</span><span class="pln">
$count </span><span class="pun">=</span><span class="pln"> count</span><span class="pun">(</span><span class="pln">$terms</span><span class="pun">);</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">$count </span><span class="pun">></span> <span class="lit">0</span><span class="pun">){</span>
<span class="kwd">foreach</span> <span class="pun">(</span><span class="pln">$terms </span><span class="kwd">as</span><span class="pln"> $term</span><span class="pun">)</span> <span class="pun">{</span> <span class="pun">?></span>
<span class="tag"><url></span>
<span class="tag"><loc></span><span class="pun"><?</span><span class="pln">php echo get_term_link</span><span class="pun">(</span><span class="pln">$term</span><span class="pun">,</span><span class="pln"> $term</span><span class="pun">-></span><span class="pln">slug</span><span class="pun">);</span> <span class="pun">?></span><span class="tag"></loc></span>
<span class="tag"><changefreq></span><span class="pln">weekly</span><span class="tag"></changefreq></span>
<span class="tag"><priority></span><span class="pln">0.8</span><span class="tag"></priority></span>
<span class="tag"></url></span>
<span class="pun"><?</span><span class="pln">php </span><span class="pun">}}</span> <span class="com">/* 分类循环结束 */</span><span class="pun">?></span>
<span class="pun"><?</span><span class="pln">php
</span><span class="com">/* 标签(可选) */</span><span class="pln">
$tags </span><span class="pun">=</span><span class="pln"> get_terms</span><span class="pun">(</span><span class="str">"post_tag"</span><span class="pun">);</span>
<span class="kwd">foreach</span> <span class="pun">(</span><span class="pln"> $tags </span><span class="kwd">as</span><span class="pln"> $key </span><span class="pun">=></span><span class="pln"> $tag </span><span class="pun">)</span> <span class="pun">{</span><span class="pln">
$link </span><span class="pun">=</span><span class="pln"> get_term_link</span><span class="pun">(</span><span class="pln"> intval</span><span class="pun">(</span><span class="pln">$tag</span><span class="pun">-></span><span class="pln">term_id</span><span class="pun">),</span> <span class="str">"post_tag"</span> <span class="pun">);</span>
<span class="kwd">if</span> <span class="pun">(</span><span class="pln"> is_wp_error</span><span class="pun">(</span><span class="pln"> $link </span><span class="pun">)</span> <span class="pun">)</span>
<span class="kwd">return</span> <span class="kwd">false</span><span class="pun">;</span><span class="pln">
$tags</span><span class="pun">[</span><span class="pln"> $key </span><span class="pun">]-></span><span class="pln">link </span><span class="pun">=</span><span class="pln"> $link</span><span class="pun">;</span>
<span class="pun">?></span>
<span class="tag"><url></span>
<span class="tag"><loc></span><span class="pun"><?</span><span class="pln">php echo $link </span><span class="pun">?></span><span class="tag"></loc></span>
<span class="tag"><changefreq></span><span class="pln">monthly</span><span class="tag"></changefreq></span>
<span class="tag"><priority></span><span class="pln">0.4</span><span class="tag"></priority></span>
<span class="tag"></url></span>
<span class="pun"><?</span><span class="pln">php </span><span class="pun">}</span> <span class="com">/* 标签循环结束 */</span> <span class="pun">?></span>
<span class="tag"></urlset></span>

代码生成XML需要实现伪静态:
Apache主机,在.htaccess文件中添加以下重写规则:

<span class="typ">RewriteEngine</span> <span class="typ">On</span>
<span class="typ">RewriteBase</span> <span class="pun">/</span>
<span class="typ">RewriteRule</span> <span class="pun">^</span><span class="pln">sitemap</span><span class="pun">.</span><span class="pln">xml$ xmlmap</span><span class="pun">.</span><span class="pln">php</span>

nginx主机,在.htaccess文件中添加以下重写规则:

<span class="pln">rewrite </span><span class="pun">^</span><span class="str">/sitemap.xml$ /</span><span class="pln">xmlmap</span><span class="pun">.</span><span class="pln">php</span><span class="pun">;</span>

IIS主机,在web.config文件中添加以下重写规则:

<span class="tag"><rule</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"Rewrite to xmlmap.php"</span><span class="atn">stopProcessing</span><span class="pun">=</span><span class="atv">"true"</span><span class="tag">></span>
<span class="tag"><match</span> <span class="atn">url</span><span class="pun">=</span><span class="atv">"^sitemap.xml"</span> <span class="tag">/></span>
<span class="tag"><action</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"Rewrite"</span> <span class="atn">url</span><span class="pun">=</span><span class="atv">"xmlmap.php"</span> <span class="tag">/></span>
<span class="tag"></rule></span>

HTML地图生成

和XML一样,新建PHP文件sitemap.php,复制下方代码进去,上传到主题目录,注意不要上传到网站根目录。

<span class="pun"><?</span><span class="pln">php</span>
<span class="com">/*
Template Name: Sitemap
*/</span>
<span class="pun">?></span>
<span class="dec"><!DOCTYPE html PUBLIC </span><span class="dec">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span><span class="dec">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span class="dec">></span>
<span class="tag"><html</span> <span class="atn">xmlns</span><span class="pun">=</span><span class="atv">"http://www.w3.org/1999/xhtml"</span><span class="tag">></span>
<span class="tag"><head</span> <span class="atn">profile</span><span class="pun">=</span><span class="atv">"http://gmpg.org/xfn/11"</span><span class="tag">></span>
<span class="pln"><meta http-equiv=</span><span class="pln">"Content-Type"</span><span class="pln">content=</span><span class="pln">"text/html; charset=</span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span> <span class="str">'charset'</span> <span class="pun">);</span> <span class="pun">?></span><span class="pln">"</span><span class="pln"> /></span>
<span class="tag"><title></span><span class="pln"><a href="http://www.ooomg.cn/tag/%e7%ab%99%e7%82%b9%e5%9c%b0%e5%9b%be" title="查看与 站点地图 相关的文章" target="_blank">站点地图</a>_</span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'name'</span><span class="pun">);</span> <span class="pun">?></span><span class="tag"></title></span>
<span class="pln"><meta name=</span><span class="pln">"keywords"</span><span class="pln"> content=</span><span class="pln">"<a href="http://www.ooomg.cn/tag/%e7%ab%99%e7%82%b9%e5%9c%b0%e5%9b%be" title="查看与 站点地图 相关的文章" target="_blank">站点地图</a>,</span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'name'</span><span class="pun">);</span> <span class="pun">?></span><span class="pln">"</span><span class="pln"> /></span>
<span class="pln"><meta name=</span><span class="pln">"copyright"</span><span class="pln"> content=</span><span class="pln">"</span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'name'</span><span class="pun">);</span> <span class="pun">?></span><span class="pln">"</span><span class="pln"> /></span>
<span class="pln"><link rel=</span><span class="pln">"canonical"</span><span class="pln"> href=</span><span class="pln">"</span><span class="pun"><?</span><span class="pln">php echo get_permalink</span><span class="pun">();</span> <span class="pun">?></span><span class="pln">"</span><span class="pln"> /></span>
<span class="tag"><style</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"text/css"</span><span class="tag">></span>
<span class="pln">body </span><span class="pun">{</span><span class="pln">font</span><span class="pun">-</span><span class="pln">family</span><span class="pun">:</span> <span class="typ">Microsoft</span> <span class="typ">Yahei</span><span class="pun">,</span><span class="typ">Verdana</span><span class="pun">;</span><span class="pln">font</span><span class="pun">-</span><span class="pln">size</span><span class="pun">:</span><span class="lit">13px</span><span class="pun">;</span><span class="pln">margin</span><span class="pun">:</span><span class="lit">0</span> <span class="kwd">auto</span><span class="pun">;</span><span class="pln">color</span><span class="pun">:</span> <span class="com">#000000;background: #ffffff;width: </span><span class="com">990px</span><span class="com">;margin: </span><span class="com">0 </span><span class="com">auto</span><span class="com">}</span>
<span class="pln">a</span><span class="pun">:</span><span class="pln">link</span><span class="pun">,</span><span class="pln">a</span><span class="pun">:</span><span class="pln">visited </span><span class="pun">{</span><span class="pln">color</span><span class="pun">:</span><span class="com">#000;text-decoration:none;}</span>
<span class="pln">a</span><span class="pun">:</span><span class="pln">hover </span><span class="pun">{</span><span class="pln">color</span><span class="pun">:</span><span class="com">#08d;text-decoration:none;}</span>
<span class="pln">h1</span><span class="pun">,</span><span class="pln">h2</span><span class="pun">,</span><span class="pln">h3</span><span class="pun">,</span><span class="pln">h4</span><span class="pun">,</span><span class="pln">h5</span><span class="pun">,</span><span class="pln">h6 </span><span class="pun">{</span><span class="pln">font</span><span class="pun">-</span><span class="pln">weight</span><span class="pun">:</span><span class="pln">normal</span><span class="pun">;}</span>
<span class="pln">img </span><span class="pun">{</span><span class="pln">border</span><span class="pun">:</span><span class="lit">0</span><span class="pun">;}</span>
<span class="pln">li </span><span class="pun">{</span><span class="pln">margin</span><span class="pun">-</span><span class="pln">top</span><span class="pun">:</span> <span class="lit">8px</span><span class="pun">;}</span>
<span class="pun">.</span><span class="pln">page </span><span class="pun">{</span><span class="pln">padding</span><span class="pun">:</span> <span class="lit">4px</span><span class="pun">;</span><span class="pln"> border</span><span class="pun">-</span><span class="pln">top</span><span class="pun">:</span> <span class="lit">1px</span> <span class="com">#EEEEEE solid}</span>
<span class="pun">.</span><span class="pln">author </span><span class="pun">{</span><span class="pln">background</span><span class="pun">-</span><span class="pln">color</span><span class="pun">:</span><span class="com">#EEEEFF; padding: </span><span class="com">6px</span><span class="com">; border-top: </span><span class="com">1px </span><span class="com">#ddddee solid}</span>
<span class="com">#nav, #content, #footer {padding: </span><span class="com">8px</span><span class="com">; border: </span><span class="com">1px </span><span class="com">solid #EEEEEE; clear: both; width: </span><span class="com">95</span><span class="com">%; margin: </span><span class="com">auto</span><span class="com">; margin-top: </span><span class="com">10px</span><span class="com">;}</span>
<span class="tag"></style></span>
<span class="tag"></head></span>
<span class="tag"><body</span> <span class="atn">vlink</span><span class="pun">=</span><span class="atv">"#333333"</span> <span class="atn">link</span><span class="pun">=</span><span class="atv">"#333333"</span><span class="tag">></span>
<span class="tag"><h2</span> <span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">text</span><span class="pun">-</span><span class="pln">align</span><span class="pun">:</span><span class="pln"> center</span><span class="pun">;</span><span class="pln"> margin</span><span class="pun">-</span><span class="pln">top</span><span class="pun">:</span> <span class="lit">20px</span><span class="atv">"</span><span class="tag">></span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'name'</span><span class="pun">);</span> <span class="pun">?></span><span class="pln"> SiteMap </span><span class="tag"></h2></span>
<span class="tag"><center></center></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"nav"</span><span class="tag">></span><span class="pln"><a href=</span><span class="pln">"</span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'url'</span><span class="pun">);</span> <span class="pun">?></span><span class="pln">/"</span><span class="pln">></span><span class="tag"><strong></span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'name'</span><span class="pun">);</span> <span class="pun">?></span><span class="tag"></strong></a></span><span class="pln"> &raquo; <a href=</span><span class="pln">"</span><span class="pun"><?</span><span class="pln">php echo get_permalink</span><span class="pun">();</span> <span class="pun">?></span><span class="pln">"</span><span class="pln">>站点地图</span><span class="tag"></a></div></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">></span>
<span class="tag"><h3></span><span class="pln">最新文章</span><span class="tag"></h3></span>
<span class="tag"><ul></span>
<span class="pun"><?</span><span class="pln">php</span>
<span class="pln">$previous_year </span><span class="pun">=</span><span class="pln"> $year </span><span class="pun">=</span> <span class="lit">0</span><span class="pun">;</span>
<span class="pln">$previous_month </span><span class="pun">=</span><span class="pln"> $month </span><span class="pun">=</span> <span class="lit">0</span><span class="pun">;</span>
<span class="pln">$ul_open </span><span class="pun">=</span> <span class="kwd">false</span><span class="pun">;</span>
<span class="pln">$myposts </span><span class="pun">=</span><span class="pln"> get_posts</span><span class="pun">(</span><span class="str">'numberposts=-1&orderby=post_date&order=DESC'</span><span class="pun">);</span>
<span class="kwd">foreach</span><span class="pun">(</span><span class="pln">$myposts </span><span class="kwd">as</span> <span class="pln">$post</span><span class="pun">)</span> <span class="pun">:</span>
<span class="pun">?></span>
<span class="tag"><li></span><span class="pln"><a href=</span><span class="pln">"</span><span class="pun"><?</span><span class="pln">php the_permalink</span><span class="pun">();</span> <span class="pun">?></span><span class="pln">"</span><span class="pln"> title=</span><span class="pln">"</span><span class="pun"><?</span><span class="pln">php the_title</span><span class="pun">();</span> <span class="pun">?></span><span class="pln">"</span><span class="pln"> target=</span><span class="pln">"_blank"</span><span class="pln">></span><span class="pun"><?</span><span class="pln">php the_title</span><span class="pun">();</span> <span class="pun">?></span><span class="tag"></a></li></span>
<span class="pun"><?</span><span class="pln">php endforeach</span><span class="pun">;</span> <span class="pun">?></span>
<span class="tag"></ul></span>
<span class="tag"></div></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">></span>
<span class="tag"><li</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"categories"</span><span class="tag">></span><span class="pln">分类目录</span><span class="tag"><ul></span>
<span class="pun"><?</span><span class="pln">php wp_list_categories</span><span class="pun">(</span><span class="str">'title_li='</span><span class="pun">);</span> <span class="pun">?></span>
<span class="tag"></ul></li></span>
<span class="tag"></div></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">></span>
<span class="tag"><li</span> <span class="atn">class</span><span class="pun">=</span><span class="atv">"categories"</span><span class="tag">></span><span class="pln">单页面</span><span class="tag"></li></span>
<span class="pun"><?</span><span class="pln">php wp_page_menu</span><span class="pun">(</span><span class="pln"> $args </span><span class="pun">);</span> <span class="pun">?></span>
<span class="tag"></div></span>
<span class="tag"><div</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"footer"</span><span class="tag">></span><span class="pln">查看博客首页: </span><span class="tag"><strong></span><span class="pln"><a href=</span><span class="pln">"</span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'url'</span><span class="pun">);</span> <span class="pun">?></span><span class="pln">/"</span><span class="pln">></span><span class="pun"><?</span><span class="pln">php bloginfo</span><span class="pun">(</span><span class="str">'name'</span><span class="pun">);</span> <span class="pun">?></span><span class="tag"></a></strong></div><br</span> <span class="tag">/></span>
<span class="tag"><center></span>
<span class="tag"><div</span> <span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">text</span><span class="pun">-</span><span class="pln">algin</span><span class="pun">:</span><span class="pln"> center</span><span class="pun">;</span><span class="pln"> font</span><span class="pun">-</span><span class="pln">size</span><span class="pun">:</span> <span class="lit">11px</span><span class="atv">"</span><span class="tag">><strong></span><span class="pln">SiteMap</span><span class="tag"></strong></span><span class="pln"> 上次更新: </span><span class="pun"><?</span><span class="pln">php $last </span><span class="pun">=</span><span class="pln"> $wpdb</span><span class="pun">-></span><span class="pln">get_results</span><span class="pun">(</span><span class="str">"SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')"</span><span class="pun">);</span><span class="pln">$last </span><span class="pun">=</span><span class="pln"> date</span><span class="pun">(</span><span class="str">'Y-m-d'</span><span class="pun">,</span><span class="pln"> strtotime</span><span class="pun">(</span><span class="pln">$last</span><span class="pun">[</span><span class="lit">0</span><span class="pun">]-></span><span class="pln">MAX_m</span><span class="pun">));</span><span class="pln">echo $last</span><span class="pun">;</span> <span class="pun">?></span><span class="tag"><br</span> <span class="tag">/><br</span> <span class="tag">/></div></span>
<span class="tag"></center></span>
<span class="tag"></body></span>
<span class="tag"></html></span>

然后打开WordPress后台,新建页面,网站模板选择Sitemap,更改链接为网站域名/sitemap/。

 

发表评论

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