How to Create a Sitemap in WordPress with an Additional File

By . Category: PHP, Wordpress Tags:

irnanto.com – 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
    <?php
    /*
    Template Name: Sitemap-irnanto.com
    */
    ?>
    <?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(); ?>	
    	  </a></h2>
    	</div>
    	<div class=”entry siteMap”>
              <!– —————– Display Pages —————– –>
    	  <h2 id=”pages”>Pages</h2>
    	  <ul>
    	  <?php
    	  // Adding pages seprated with a comma [,] that you want to hide for display on sitemap
    	  wp_list_pages(
    		array(
    		  ‘exclude’ => ”,
    		  ‘title_li’ => ”,
    		)
    	  );
    	  ?>
    	  </ul>
              <!– —————– display Category —————– –>
    	  <h2>Categories</h2>
    	  <ul>
    		<?php wp_list_cats("sort_column=name&feed_image=/wp-content/themes/wizer/images/rss-ball.jpg&optioncount=1&hierarchical=0"); ?>
    	  </ul>
              <!– —————– Heading display with relative category —————– –>
    	  <h2 id="posts">Posts</h2>
    	  <ul>
    	  <?php
    	  // 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>”;
    		query_posts(‘posts_per_page=-1&cat=’.$cat->cat_ID);
    		while(have_posts()) {
    		  the_post();
    		  $category = get_the_category();
    
    		  for($xi=0;$xi<=5;$xi++){
    			if ($category[$xi]->cat_ID == $cat->cat_ID) {
    			  echo ‘<li><a href=”‘.get_permalink().'”>’.get_the_title().'</a></li>’;
    			}
    		  }
    		}
    		echo “</ul>”;
    		echo “</li>”;
    	  }
    	  ?>
    	  </ul>
    	</div>
      </div>
    </div>
    <?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.

Ads