How to Create a Sitemap in WordPress with an Additional File

By . Category: PHP, Wordpress Tags: – How to create a sitemap in wordpress with additional files. Sitemap is a page that displays the parts or links contained in a site. Sitemap aimed at two things, namely for search engines and for users (humans). This time I will give you a little tutorial on how to create a sitemap in wordpress for the user. here I am using wordpress CMS on the hosting service that has a facility can use the PHP file. OK we just practice how to create a sitemap in wordpress. The steps that you should follow as follows:

  1. login to your cpanel
  2. Open the file manager
  3. go to the directory of your website template that is being actively used
  4. example: public_html/wp-content/themes/name-theme
  5. create a new file with the name sitemap.php
  6. copy or type the code below on file sitemap.php
    Template Name:
    <?php get_header(); ?>
    <div id=”content” >
      <div class=”post”>
    	<div class=”title”>
    	  <h2><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
    		<?php the_title(); ?>	
    	<div class=”entry siteMap”>
              <!– —————– Display Pages —————– –>
    	  <h2 id=”pages”>Pages</h2>
    	  // Adding pages seprated with a comma [,] that you want to hide for display on sitemap
    		  ‘exclude’ => ”,
    		  ‘title_li’ => ”,
              <!– —————– display Category —————– –>
    		<?php wp_list_cats("sort_column=name&feed_image=/wp-content/themes/wizer/images/rss-ball.jpg&optioncount=1&hierarchical=0"); ?>
              <!– —————– Heading display with relative category —————– –>
    	  <h2 id="posts">Posts</h2>
    	  // Add a category seprated with a comma (,) you want to hide for display on sitemap
    	  $cats = get_categories(‘exclude=’);
    	  foreach ($cats as $cat) {
    		echo “<li><h3>”.$cat->cat_name.”</h3>”;
    		echo “<ul>”;
    		while(have_posts()) {
    		  $category = get_the_category();
    			if ($category[$xi]->cat_ID == $cat->cat_ID) {
    			  echo ‘<li><a href=”‘.get_permalink().'”>’.get_the_title().'</a></li>’;
    		echo “</ul>”;
    		echo “</li>”;
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  7. save the file sitemap.php
  8. login to your-domain/wp-admin
  9. click menu page
  10. select add new
  11. type the title “Sitemap” without quotes
  12. on the Page Attributes -> Templates
    Page of Attributes

    Page of Attributes

  13. select sitemap
  14. click Publish

Now look at the results on your web menu. For a demo please visit this website. Among tutorial how to create a sitemap in wordpress with additional files, may be useful for all of us, Aamiin.