Wordpress Simple Sitemap


/ Published in: PHP
Save to your folder(s)

Create a sitemap in wordpress, including posts, categories and pages just use the [sitemap] shortcode within the post content and wordpress / the function does the rest.


Copy this code and paste it in your HTML
  1. /**
  2. * Makes a simple sitemap from just one shortcode
  3. * Usage: [sitemap]
  4. * How to: Add the function and the shortcode to your functions.php and add shortcode to any page
  5. */
  6.  
  7. function simple_sitemap(){
  8. global $wpdb;
  9. $args = array('depth' => 0,
  10. 'show_date' => NULL,
  11. 'date_format' => get_option('date_format'),
  12. 'child_of' => 0,
  13. 'exclude' => NULL,
  14. 'include' => NULL,
  15. 'title_li' => '<span class="subhead3">Pages</span>',
  16. 'echo' => 1,
  17. 'authors' => NULL,
  18. 'sort_column' => 'menu_order, post_title',
  19. 'link_before' => NULL,
  20. 'link_after' => NULL,
  21. 'exclude_tree' => NULL );
  22.  
  23. echo '<div id="sitemap"><ul>';
  24. wp_list_pages($args);
  25. echo '</ul>';
  26.  
  27. $args = array('show_option_all' => NULL,
  28. 'orderby' => 'name',
  29. 'order' => 'ASC',
  30. 'show_last_update' => 0,
  31. 'style' => 'list',
  32. 'show_count' => 0,
  33. 'hide_empty' => 1,
  34. 'use_desc_for_title' => 1,
  35. 'child_of' => 0,
  36. 'feed' => NULL,
  37. 'feed_type' => NULL,
  38. 'feed_image' => NULL,
  39. 'exclude' => NULL,
  40. 'exclude_tree' => NULL,
  41. 'include' => NULL,
  42. 'hierarchical' => true,
  43. 'title_li' => '<span class="subhead3">Categories</span>',
  44. 'number' => NULL,
  45. 'echo' => 1,
  46. 'depth' => 0,
  47. 'current_category' => 0,
  48. 'pad_counts' => 0,
  49. 'taxonomy' => 'category',
  50. 'walker' => 'Walker_Category' );
  51.  
  52. echo '<ul>';
  53. echo wp_list_categories( $args );
  54. echo '</ul>';
  55. echo '</div>';
  56. }
  57. add_shortcode('sitemap', 'simple_sitemap');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.