Blog Code Forum

SiteMap

From Wiki.cyring.fr

Jump to: navigation, search

Contents

Function SiteMap for WordPress

The PHP function

  1. function fSiteMap( $atts ) {
  2. 	$fstring = '<div id="SiteMap"><ul>';
  3. 	foreach(get_categories('orderby=name') as $category) {
  4. 		$fstring = $fstring . '<li><input type="checkbox" checked="checked" id=' . $category->cat_ID . ' /><label for=' . $category->name . '>' . $category->name . '</label><ul>';
  5. 		foreach(get_posts('numberposts=-1&category=' . $category->cat_ID) as $item)
  6. 			$fstring = $fstring . '<li>' . strftime("%x ", strtotime($item->post_date)) . '<a href=' . get_permalink($item->ID) . '>' . get_the_title($item->ID) . '</a> (' . $item->comment_count . ')</li>';
  7. 		$fstring = $fstring . '</ul></li>';
  8. 	}
  9. 	$fstring = $fstring . '</ul></div>';
  10. 	return ($fstring);
  11. }

Instancing into the WordPress theme loop

  1. function twentyten_setup() {
  2. 	// ...
  3. 	add_shortcode( 'sitemap', 'fSiteMap' );
  4. }

Inserting into a page

Just add [sitemap] anywhere in your page.

CyrIng-SiteMap.png

Personal tools