How to Create Word Press Sitemap?


Hi Guys I previously explained XML Site map, now i explained WordPress sitemap.

You functions.php and but below code, This is archives link :

// Sitemap  14 Feb 2012
function month_displayArchives() {
global $month, $wpdb, $wp_version;

// a mysql query to get the list of distinct years and months that posts have been created
$sql = ‘SELECT
DISTINCT YEAR(post_date) AS year,
MONTH(post_date) AS month,
count(ID) as posts
FROM ‘ . $wpdb->posts . ‘
WHERE post_status=”publish”
AND post_type=”post”
AND post_password=””
GROUP BY YEAR(post_date),
MONTH(post_date)
ORDER BY post_date DESC’;

// use get_results to do a query directly on the database
$archiveSummary = $wpdb->get_results($sql);

// if there are any posts
if ($archiveSummary) {
// loop through the posts
foreach ($archiveSummary as $date) {
// reset the query variable
unset ($bmWp);
// create a new query variable for the current month and year combination
$bmWp = new WP_Query(‘year=’ . $date->year . ‘&monthnum=’ . zeroise($date->month, 2) . ‘&posts_per_page=-1’);

// if there are any posts for that month display them
if ($bmWp->have_posts()) {
// display the archives heading
$url = get_month_link($date->year, $date->month);
$text = $month[zeroise($date->month, 2)] . ‘ ‘ . $date->year;

echo get_archives_link($url, $text, ”, ‘<h4>’, ‘</h4>’);
echo ‘<ul>’;

// display an unordered list of posts for the current month
while ($bmWp->have_posts()) {
$bmWp->the_post();
echo ‘<li><a href=”‘ . get_permalink($bmWp->post) . ‘” title=”‘ . wp_specialchars($text, 1) . ‘”>’ . wptexturize($bmWp->post->post_title) . ‘</a></li>’;
}

echo ‘</ul>’;
}
}
}
}

then you create one “template page”. That page inside put this code :

<?php

// Post by archive month
echo “<h3>Monthly Archives</h3>”;
echo month_displayArchives();
?>

At the same time you put below code also :
<?php
// All Pages Display
$args = array(
‘depth’        => 0,
‘show_date’    => ”,
‘date_format’  => get_option(‘date_format’),
‘child_of’     => 0,
‘exclude’      => ”,
‘include’      => ”,
‘title_li’     => __(”),
‘echo’         => 1,
‘authors’      => ”,
‘sort_column’  => ‘menu_order, post_title’,
‘link_before’  => ”,
‘link_after’   => ”,
‘walker’       => ” );

echo “<h3>All Pages</h3><ul>”;
wp_list_pages( $args );
echo “</ul>”;

// All Posts Link
echo “<h3>All Posts</h3><ul>”;

$args = array(‘orderby’ => ‘date’, ‘order’=> ‘DESC’); // This all post display
$postslist = get_posts( $args );
$i; //This is counting the iteam purpose using
foreach ($postslist as $post) :  setup_postdata($post);
$i++; // This is increasing howmany foreach going that is purpose using.

echo “<li>”;
echo “<a href=”.get_permalink($page->ID).”>”;
echo the_title();
echo “</a></li>”;
endforeach;

echo “</ul>”;

// Wp categories List
$cargs = array(
‘show_option_all’    => ”,
‘orderby’            => ‘name’,
‘order’              => ‘ASC’,
‘show_last_update’   => 0,
‘style’              => ‘list’,
‘show_count’         => 0,
‘hide_empty’         => 1,
‘use_desc_for_title’ => 1,
‘child_of’           => 0,
‘feed’               => ”,
‘feed_type’          => ”,
‘feed_image’         => ”,
‘exclude’            => ”,
‘exclude_tree’       => ”,
‘include’            => ”,
‘hierarchical’       => true,
‘title_li’           => __( ” ),
‘show_option_none’   => __(‘No categories’),
‘number’             => NULL,
‘echo’               => 1,
‘depth’              => 0,
‘current_category’   => 0,
‘pad_counts’         => 0,
‘taxonomy’           => ‘category’,
‘walker’             => ‘Walker_Category’ );

echo “<h3>All Categories</h3><ul>”;
wp_list_categories( $cargs );
echo “</ul>”;

// All Archives List
$aargs = array(
‘type’            => ‘monthly’,
‘limit’           => ”,
‘format’          => ‘html’,
‘before’          => ”,
‘after’           => ”,
‘show_post_count’ => false,
‘echo’            => 1 );

echo “<h3>All Archives</h3><ul>”;
wp_get_archives( $aargs );
echo “</ul>”;

?>

Now you have ready for wordpress sitemap. If you have more knowledge create your style sitemap.
Happy to all 🙂

Comments are closed.