Using Templates to create a WordPress Sitemap

There is a feature in WordPress, sometimes overlooked, which makes it very versatile, especially for those who create themes: the use of templates! A Template is not just 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:

1
2
3
/ *
Template Name: Sitemap
* /

Using 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 the comment shown above) and loaded in the folder of your theme, you will notice that the editor during the creation of a WordPress page (not a post) menu Template (below) will contain the name of the template file is loaded. As indicated in the template section:

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) can show a real sitemap for your blog.

Creating a page Sitemap

First create a file sitemap.php and upload the folder of your theme. WordPress by creating a new page, give it a name and select the template from the menu that is located below the editor! Finished!

The template, as part of the theme, it also contains all the structure of the theme itself is therefore important to know and write properly. But here is a skeleton of a Sitemap that you can modify to reflect the theme you have installed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<Php
/ *
Template Name: Sitemap
* /
?>
<? Php get_header ();?>
"content" > < div id = "content">
have_posts ( ) ) : the_post ( ) ; ?> <? Php if (have_posts ()): while (have_posts ()): the_post ();?>
"post" id = "post-<?php the_ID(); ?> "> < div class = "post" id = "post-<? php the_ID ();?>">
h2 > < h2 > <? php the_title ();?> </ h2 >
"date-time" ><?php the_time ( 'lj F, Y' ) ?>< / small > < small class = "date-time"> <? php the_time ('lj F, Y')?> </ small >
"entry" > < div class = "entry">
href = "<?php bloginfo('url'); ?> " alt=" <?php bloginfo ( 'name' ) ; ?> ">Home < / a >< / strong >< / p > < p > < strong > < a href = "<? php bloginfo ('url');?>" alt = "<? php bloginfo ('name');?>"> Home </ a > </ p > </ p >
h3 > < h3 > Page </ h3 >
< ul >
; ?> <? Php wp_list_pages ('title_li =');?>
</ ul >
h3 > < h3 > Post </ h3 >
< ul >
) ; <Php $ archive_query = new WP_Query ('showposts = 1000');
while ($ archive_query-> have_posts ()): $ archive_query-> the_post ();?>
= "<?php the_permalink() ?> " rel="bookmark" title="Permanent Link to <?php the_title ( ) ; ?> "> <?php the_title ( ) ; ?>< / a >< / li > < will > < a href = "<? php the_permalink ()?>" rel = "bookmark" title = "Permanent Link to <? php the_title ();?>"> <? php the_title ();?> </ a > </ them >
<? Php endwhile;?>
</ ul >
h3 > < h3 > Monthly Archives </ h3 >
< ul >
; ?> <? Php wp_get_archives ('type = monthly');?>
</ ul >
h3 > < h3 > Category </ h3 >
< ul >
; ?> <? Php wp_list_categories ('title_li = 0');?>
</ ul >
h3 > < h3 > RSS Feeds / FeedBurner </ h3 >
< ul >
= "<?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 > < will > < 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 feeds </ a > </ them >
= "<?php bloginfo('rss_url'); ?> " alt="RSS 0.92 feed"> < acronym title = "Really Simple Syndication" > RSS < / acronym > 0.92 feed < / a >< / li > < will > < a href = "<? php bloginfo ('rss_url');?>" alt = "RSS 0.92 feed"> < acronym title = "Really Simple Syndication"> RSS </ acronym > 0.92 feed </ a > </ them >
= "<?php bloginfo('rss2_url'); ?> " alt="RSS 2.0 feed"> < acronym title = "Really Simple Syndication" > RSS < / acronym > 2.0 feed < / a >< / li > < will > < a href = "<? php bloginfo ('rss2_url');?>" alt = "RSS 2.0 feed"> < acronym title = "Really Simple Syndication"> RSS </ acronym > 2.0 feeds </ a > </ them >
= "<?php bloginfo('atom_url'); ?> " alt="Atom feed">Atom feed < / a >< / li > < will > < a href = "<? php bloginfo ('atom_url');?>" alt = "Atom feed"> Atom feed </ a > </ them >
</ ul >
</ div >
</ div >
<? Php endwhile, endif;?>
</ div >
<? Php get_sidebar (); get_footer ();?>

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

  1. October 13, 2008 Lu *:

    Muito useful! :)

  2. November 23, 2008 Torsten :

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

  3. March 2, 2009 fuses :

    Very useful post! Thank you!

Leave a comment

XHTML TAG PERMIT: <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 [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA