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.
<?php
/*
Plugin Name: Site Map
Plugin Author: Sue
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 &lt;!&ndash;&ndash; sitemap &ndash;&ndash;&gt; on any page in code view to display the site map.
Plugin Author URI: http://endless-sonata.net
Plugin URI: /wp-admin/plugin-editor.php?file=sitemap.php
*/
function sitemap() {
echo "<ul>";
wp_list_pages('title_li=');
echo "</ul>";
/*
// optional list categories
echo "<ul>";
wp_list_categories('title_li=');
echo "</ul>";
// you may add any other list options you'd like
*/
}
function generate_sitemap($content) {
if (strpos($content, "<!-- sitemap -->") !== FALSE) {
$content = preg_replace('/<p>\s*<!--(.*)-->\s*<\/p>/i', "<!--$1-->", $content);
$content = str_replace('<!-- sitemap -->', sitemap(), $content);
}
return $content;
}
add_filter('the_content', 'generate_sitemap');
?>
Thanks for your comment: Babyjen, Chien Yee, Vickie, Anya, Marsha, YaraPosted in
Tutorials | by
Sue |
6 Comments »
