Using WordPress Template for creating a Sitemap

Wednesday, July 16, 2008

Is there a feature in WordPress, sometimes overlooked, which makes it very versatile, especially for those who create themes: the use of Template! A template is simply a file included in the theme folder. To identify it as a template just insert a special comment at the beginning of the file in PHP:

PHP:
  1. / *
  2. Template Name: Sitemap
  3. * /

Leveraging this feature you can create a blank page, with the standard procedure of WordPress, and connect it to our template. If you create a file, for example sitemap.php (adding that comment indicated above) and loads it in the folder of your theme, you'll notice that WordPress editor when creating a page (not a post) menu Template (below) will contain the name of the template file loaded. As mentioned in section template:

Some themes have custom templates you can use for certain pages that may contain additional features or custom graphics. [...]

I, for example, I used this feature to create a dynamic page (which then executes PHP code) that shows a real sitemap of your blog.

Creating a Sitemap page

First create a file sitemap.php and load inside the folder of your theme. Wordpress created by a new page, give it a name and select the Template from the menu that is located below the editor! Finished!

The template, being part of the theme, also contains the entire structure of the theme itself and is therefore important to know that he writes correctly. Yet here is a skeleton of a Sitemap that you can tailor the theme you have installed:

HTML:
  1. <? Php
  2. / *
  3. Template Name: Sitemap
  4. * /
  5. ?>
  6. <? Php get_header ();?>
  7. "content" > <div id = "content">
  8. : while ( have_posts ( ) ) : the_post ( ) ; ? > <? Php if (have_posts ()): while (have_posts ()): the_post ();?>
  9. "post" id = "post-<?php the_ID(); ?> "> <div class = "post" id = "post-<? php the_title ();?>">
  10. <h2> <? php the_title ();?> </ h2>
  11. "date-time" ><?php the_time ( 'lj F, Y' ) ?>< / small> <small class = "date-time"> <? php the_time ( 'lj F Y')?> </ small>
  12. "entry" > <div class = "entry">
  13. " alt=" < ?php bloginfo ( 'name' ) ; ? > ">Home < / a>< / strong>< / p> <p> <strong> <a href = "<? php bloginfo ( 'url');?>" alt = "<? php bloginfo ( 'name');?>"> Home </ a> </ strong> </ p>
  14. <h4> Pages </ h4>
  15. ) ; ? > <? Php wp_list_pages ( 'title_li =');?>
  16. <h4> Post </ h4>
  17. 'showposts=1000' ) ; <? Php $ archive_query wp_query = new ( 'showposts = 1000');
  18. have_posts()) : $archive_query->the_post(); ?> while ($ archive_query-> have_posts ()): $ archive_query-> the_post ();?>
  19. " rel="bookmark" title="Permanent Link to < ?php the_title ( ) ; ? > "> < ?php the_title ( ) ; ?>< / a>< / li> <li> <a href = "<? php the_permalink ();?>" rel = "bookmark" title = "Permanent Link to <? php the_title ();?>"> <? php the_title ();?> </ a> </ li>
  20. <h4> Monthly Archives </ h4>
  21. ) ; ? > <? Php wp_get_archives ( 'type = monthly');?>
  22. <h4> Categories </ h4>
  23. ) ; ? > <? Php wp_list_categories ( 'title_li = 0');?>
  24. <h4> Feeds RSS / FeedBurner </ h4>
  25. " alt="RDF/RSS 1.0 feed"> <acronym title = "Resource Description Framework" > RDF </acronym> / <acronym title = "Really Simple Syndication" > RSS </acronym> 1.0 feed < / a>< / li> <li> <a href = "<? php bloginfo ( 'rdf_url');?>" alt = "RDF / RSS 1.0 feed"> <acronym title = "Resource Description Framework"> RDF </ acronym> / <acronym title = "Really Simple Syndication"> RSS </ acronym> 1.0 feed </ a> </ li>
  26. " alt="RSS 0.92 feed"> <acronym title = "Really Simple Syndication" > RSS </acronym> 0.92 feed < / a>< / li> <li> <a href = "<? php bloginfo ( 'rss_url');?>" alt = "RSS 0.92 feed"> <acronym title = "Really Simple Syndication"> RSS </ acronym> 0.92 feed </ a> </ li>
  27. " alt="RSS 2.0 feed"> <acronym title = "Really Simple Syndication" > RSS </acronym> 2.0 feed < / a>< / li> <li> <a href = "<? php bloginfo ( 'rss2_url');?>" alt = "RSS 2.0 feed"> <acronym title = "Really Simple Syndication"> RSS </ acronym> 2.0 feed </ a> </ li>
  28. " alt="Atom feed">Atom feed < / a>< / li> <li> <a href = "<? php bloginfo ( 'atom_url');?>" alt = "Atom feed"> Atom feed </ a> </ li>
  29. <? Php endwhile; endif;?>
  30. ; ? > <? Php endif (); get_footer ();?>

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

4 comments to "Using WordPress Template to create a Sitemap"

  1. getAvatar 1.0
    October 13, 2008 Mon *:

    Muito útil! :)

  2. getAvatar 1.0
    November 23, 2008 Torsten:

    An der deutschen Übersetzung solltest du aber noch etwas arbeiten.

  3. getAvatar 1.0
  4. getAvatar 1.0
    02 mar, 2009 fuses:

    Useful post! Thank you!

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL