<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>润物无声 &#187; sitemap</title>
	<atom:link href="http://blog.zhourunsheng.com/tag/sitemap/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zhourunsheng.com</link>
	<description>天空一朵雨做的云</description>
	<lastBuildDate>Sat, 08 May 2021 05:17:21 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>为WordPress建立Html格式的Sitemap</title>
		<link>http://blog.zhourunsheng.com/2012/06/%e4%b8%bawordpress%e5%bb%ba%e7%ab%8bhtml%e6%a0%bc%e5%bc%8f%e7%9a%84sitemap/</link>
		<comments>http://blog.zhourunsheng.com/2012/06/%e4%b8%bawordpress%e5%bb%ba%e7%ab%8bhtml%e6%a0%bc%e5%bc%8f%e7%9a%84sitemap/#comments</comments>
		<pubDate>Sun, 24 Jun 2012 03:56:39 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[Web设计]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[sitemap]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=1626</guid>
		<description><![CDATA[<p>熟悉wordpress建站的童鞋都知道sitemap的重要性，尤其是对网站的SEO以及各大重要搜索引擎的索引都 [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2012/06/%e4%b8%bawordpress%e5%bb%ba%e7%ab%8bhtml%e6%a0%bc%e5%bc%8f%e7%9a%84sitemap/">为WordPress建立Html格式的Sitemap</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>熟悉wordpress建站的童鞋都知道sitemap的重要性，尤其是对网站的SEO以及各大重要搜索引擎的索引都有重要的作用，wordpress已经有许多优秀的sitemap生成插件可以使用，不过他们大部分生成的都只是xml格式的数据，可以直接提交到搜索引擎，方便搜索引擎的索引，但是不方便访客的阅读。</p>
<p>本文介绍一下怎样客制化和建立自己的Sitemap Page页面，可以包括或者排除特定的页面，特定的分类，加入自己定制的信息等等。<span id="more-1626"></span></p>
<h2>建立步骤</h2>
<p>1. 为了代码的重用，我们需要利用wordpress主题模板的特性（theme partial），在当前的主题文件夹下面新建立一个partials文件夹，然后在里面新建立一个sitemap.php文件，内容如下：</p>
<pre>&lt;h2 id="authors"&gt;Authors&lt;/h2&gt;
&lt;ul&gt;
&lt;?php
wp_list_authors(
array(
'exclude_admin' =&gt; false,
)
);
?&gt;
&lt;/ul&gt;

&lt;h2 id="pages"&gt;Pages&lt;/h2&gt;
&lt;ul&gt;
&lt;?php
// Add pages you'd like to exclude in the exclude here
wp_list_pages(
array(
'exclude' =&gt; '',
'title_li' =&gt; '',
)
);
?&gt;
&lt;/ul&gt;

&lt;h2 id="posts"&gt;Posts&lt;/h2&gt;
&lt;ul&gt;
&lt;?php

// Add categories you'd like to exclude in the exclude here
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
echo "&lt;li&gt;&lt;h3&gt;".$cat-&gt;cat_name."&lt;/h3&gt;";
echo "&lt;ul&gt;";
query_posts('posts_per_page=-1&amp;cat='.$cat-&gt;cat_ID);
while(have_posts()) {
the_post();
$category = get_the_category();
// Only display a post link once, even if it's in multiple categories
if ($category[0]-&gt;cat_ID == $cat-&gt;cat_ID) {
echo '&lt;li&gt;&lt;a href="'.get_permalink().'"&gt;'.get_the_title().'&lt;/a&gt;&lt;/li&gt;';
}
}
echo "&lt;/ul&gt;";
echo "&lt;/li&gt;";
}

//Add Custom Post Types to your HTML Sitemap
foreach( get_post_types( array('public' =&gt; true) ) as $post_type ) {
if ( in_array( $post_type, array('post','page','attachment') ) )
continue;

$pt = get_post_type_object( $post_type );

echo '&lt;h2&gt;'.$pt-&gt;labels-&gt;name.'&lt;/h2&gt;';
echo '&lt;ul&gt;';

query_posts('post_type='.$post_type.'&amp;posts_per_page=-1');
while( have_posts() ) {
the_post();
echo '&lt;li&gt;&lt;a href="'.get_permalink().'"&gt;'.get_the_title().'&lt;/a&gt;&lt;/li&gt;';
}

echo '&lt;/ul&gt;';
}
?&gt;
&lt;/ul&gt;</pre>
<p>2. 拷贝一份当前主题下面的page.php，并重新命名为page-sitemap.php,编辑内容如下：</p>
<pre>&lt;?php
/*
Template Name: Sitemap Page
*/
?&gt;
&lt;?php get_header(); ?&gt;
&lt;div id="content"&gt;
&lt;?php if (have_posts()) : ?&gt;&lt;?php while (have_posts()) : the_post(); ?&gt;
&lt;!-- menu --&gt;
&lt;div id="map"&gt;
&lt;div class="browse"&gt;现在位置 ＞&lt;a title="返回首页" href="&lt;?php echo get_settings('Home'); ?&gt;/"&gt;首页&lt;/a&gt; ＞&lt;?php the_title(); ?&gt;&lt;/div&gt;
&lt;div id="feed"&gt;&lt;a href="&lt;?php echo get_option('swt_rsssub'); ?&gt;" title="RSS"&gt;RSS&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;!-- end: menu --&gt;
&lt;!-- entry --&gt;
&lt;div class="clear"&gt;&lt;/div&gt;
&lt;div class="entry_box_s"&gt;
&lt;div class="entry"&gt;
&lt;div class="page" id="post-&lt;?php the_ID(); ?&gt;"&gt;
&lt;?php the_content('More &amp;raquo;'); ?&gt;
&lt;div class="clear"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;?php get_template_part('/partials/sitemap'); ?&gt;
&lt;/div&gt;
&lt;!-- end: entry --&gt;
&lt;div class="clear"&gt;&lt;/div&gt;
&lt;i class="lt"&gt;&lt;/i&gt;
&lt;i class="rt"&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;div class="entry_sb"&gt;
&lt;i class="lb"&gt;&lt;/i&gt;
&lt;i class="rb"&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;
&lt;/div&gt;
&lt;!-- end: content --&gt;
&lt;?php get_sidebar(); ?&gt;
&lt;?php get_footer(); ?&gt;</pre>
<p>主要修改两个地方，一个是在文件的顶部加入</p>
<pre> &lt;?php
/*
Template Name: Sitemap Page
*/
?&gt;</pre>
<p>另一个是调用sitemap.php,加入</p>
<pre> &lt;?php get_template_part('/partials/sitemap'); ?&gt;</pre>
<p>3. 新建立一个页面，模板选择“Sitemap Page”，示例 <a href="http://blog.zhourunsheng.com/sitemap/">http://blog.zhourunsheng.com/sitemap/</a></p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2012/06/%e4%b8%bawordpress%e5%bb%ba%e7%ab%8bhtml%e6%a0%bc%e5%bc%8f%e7%9a%84sitemap/">为WordPress建立Html格式的Sitemap</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2012/06/%e4%b8%bawordpress%e5%bb%ba%e7%ab%8bhtml%e6%a0%bc%e5%bc%8f%e7%9a%84sitemap/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
