Simple Site Map Plugin

I created a site map plugin for Wordpress that simply lists all the pages you have on your site. It also comes with an optional category listing. You can edit the plugin to your liking. It was easy to create since it only has two main functions. The first function sitemap lists the pages using the wordpress generated tag wp_list_pages. I’ve also commented out a categories listing. You can add other listings if you’d like. The second major function generate_sitemap creates a shortcut you can use on any page you create when you go to Write –>Page. All you need to do is insert <– sitemap –> anywhere on that page and hit Publish.

Copy and paste the code below into a text editor such as notepad, and save it as sitemap.php. Then upload it to your site’s plugins folder. Activate the plugin in the Dashboard and create your site map page. To see a working site map, click here. If you have any questions, feel free to ask.

<br />
<?php<br />
/*<br />
Plugin Name: Site Map<br />
Plugin Author: Sue<br />
Plugin Description: Generates a site map based on pages but is customizable via plugin editor. You can get to that by clicking on the title of this plugin. Use &amp;lt;!&amp;ndash;&amp;ndash; sitemap &amp;ndash;&amp;ndash;&amp;gt; on any page in code view to display the site map.<br />
Plugin Author URI: http://endless-sonata.net<br />
Plugin URI: /wp-admin/plugin-editor.php?file=sitemap.php<br />
*/<br />
function sitemap() {<br />
echo "<ul>";<br />
wp_list_pages('title_li=');<br />
echo "</ul>";<br />
/*<br />
// optional list categories<br />
echo "<ul>";<br />
wp_list_categories('title_li=');<br />
echo "</ul>";<br />
// you may add any other list options you'd like<br />
*/<br />
}<br />
function generate_sitemap($content) {<br />
if (strpos($content, "<!-- sitemap -->") !== FALSE) {<br />
$content = preg_replace('/<p>\s*<!--(.*)-->\s*<\/p>/i', "<!--$1-->", $content);<br />
$content = str_replace('<!-- sitemap -->', sitemap(), $content);<br />
}<br />
return $content;<br />
}</p>
<p>add_filter('the_content', 'generate_sitemap');<br />
?><br />

Similar Posts

Creating a RSS Feeds Page,

6 Responses to “Simple Site Map Plugin”

Thank you for taking the time to leave a message. Your comment is much appreciated. Also, please leave a comment relevant to the posted topic. If this is your first time commenting, your comment will be held for moderation before being displayed. If you would like a custom avatar to appear beside your message, please sign up for an account on Gravatar
Yara Identicon Icon Yara

It’s great to see you helping out and coding for others :) . I suck at coding myself haha :P !

Marsha Identicon Icon Marsha

Ooh, interesting! I’ve always wanted to learn PHP, and did manage to understand a bit while converting my layouts to WP. Hopefully I’ll get more time to figure it out after I graduate!

Anya Identicon Icon Anya

That’s great! Now all my pages don’t have to be listed on my index! :)

Vickie Identicon Icon Vickie

Oh, looks really interesting. My blog is not complex enough to require a site map yet; but if it ever does one day, I’ll remember to try yours out. :)

Chien Yee Identicon Icon Chien Yee

Did I ever mention how much you rock? Because you do :P

Babyjen Identicon Icon Babyjen

wow.. you made that script? cool! I’m using one now. ;) The one made by Dominic Foster.

Take Care!
-xoxo-

Leave a Reply

Quicktags: