HTML sitemaps (as opposed to XML sitemaps) are often mentioned as being useful for SEO. They certainly are if you use them wisely (and especially Bing seems to like them at times), but I like them even more for the fact that users like them a lot.
There's plenty of plugins out there that will help you make an HTML sitemap. It's not a feature in my WordPress SEO plugin just yet, but it might become one. The issue is though, that in most cases, you'll want to do specific things with your sitemaps, include or exclude certain pages / post types, show certain taxonomies, etc. That's why I tend to advice people to create a Sitemap Page template in their theme and use that.
In fact, I advise you to use a theme partial, so you can reuse your HTML sitemap template on your WordPress 404 error pages too. To do that, follow these steps: first of all, create a partials folder within your theme folder. In that partials folder, create a file called sitemap.php.
Paste the following code into that file and adapt as needed for your site:
<h2 id="authors">Authors</h2> <ul> <?php wp_list_authors( array( 'exclude_admin' => false, ) ); ?> </ul> <h2 id="pages">Pages</h2> <ul> <?php // Add pages you'd like to exclude in the exclude here wp_list_pages( array( 'exclude' => '', 'title_li' => '', ) ); ?> </ul> <h2 id="posts">Posts</h2> <ul> <?php // Add categories you'd like to exclude in the exclude here $cats = get_categories('exclude='); foreach ($cats as $cat) { echo "<li><h3>".$cat->cat_name."</h3>"; echo "<ul>"; query_posts('posts_per_page=-1&cat='.$cat->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]->cat_ID == $cat->cat_ID) { echo "<li><a href="".get_permalink()."">".get_the_title()."</a></li>"; } } echo "</ul>"; echo "</li>"; } ?> </ul>
<?php get_template_part('/partials/sitemap'); ?>
HTML Sitemap WordPress Page Template
You could do this, for instance, for a sitemap page template. To create a sitemap page template using this code, duplicate yourpage.php file and rename it to page-sitemap.php. Now open it, and below the call to the_content(); that's in there, add the get_template_part() bit mentioned above. Now go to the first line of the file, and after the opening <?php (but before get_header()), add this comment:/*
Template Name: Sitemap Page
*/
8:41 PM
Dinh Thi Lan Anh
Tags
0 nhận xét:
Post a Comment