Simple Sitemap – Automatically Generate a Responsive Sitemap - Version 1.64

Version Description

Download this release

Release Info

Developer dgwyer
Plugin Icon Simple Sitemap – Automatically Generate a Responsive Sitemap
Version 1.64
Comparing to
See all releases

Code changes from version 1.63 to 1.64

Files changed (2) hide show
  1. readme.txt +7 -4
  2. simple-sitemap.php +245 -204
readme.txt CHANGED
@@ -1,10 +1,9 @@
1
  === Simple Sitemap ===
2
  Contributors: dgwyer
3
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UUFZZU35RZPW8
4
  Tags: sitemap, html, global, sort, shortcode, pages, posts
5
  Requires at least: 2.7
6
- Tested up to: 3.9
7
- Stable tag: 1.63
8
 
9
  HTML sitemap to display content as a single linked list of posts and pages, or as groups sorted by taxonomy (via a drop-down box).
10
 
@@ -40,7 +39,7 @@ To display the shortcode on a page, or post (though it's recommended you add it
40
 
41
  Please rate this Plugin if you find it useful, thanks.
42
 
43
- See our <a href="http://www.presscoders.com" target="_blank">WordPress development site</a> for more information.
44
 
45
  == Installation ==
46
 
@@ -60,6 +59,10 @@ See our <a href="http://www.presscoders.com" target="_blank">WordPress developme
60
 
61
  == Changelog ==
62
 
 
 
 
 
63
  *1.63*
64
 
65
  * Fixed bug with CPT links.
1
  === Simple Sitemap ===
2
  Contributors: dgwyer
 
3
  Tags: sitemap, html, global, sort, shortcode, pages, posts
4
  Requires at least: 2.7
5
+ Tested up to: 4.0
6
+ Stable tag: 1.64
7
 
8
  HTML sitemap to display content as a single linked list of posts and pages, or as groups sorted by taxonomy (via a drop-down box).
9
 
39
 
40
  Please rate this Plugin if you find it useful, thanks.
41
 
42
+ See our <a href="http://www.wpgothemes.com" target="_blank">WordPress development site</a> for more information.
43
 
44
  == Installation ==
45
 
59
 
60
  == Changelog ==
61
 
62
+ *1.64 update*
63
+
64
+ * Settings page updated.
65
+
66
  *1.63*
67
 
68
  * Fixed bug with CPT links.
simple-sitemap.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php
2
  /*
3
  Plugin Name: Simple Sitemap
4
- Plugin URI: http://www.presscoders.com/plugins/free-plugins/simple-sitemap/
5
  Description: HTML sitemap to display content as a single linked list of posts and pages, or as groups sorted by taxonomy (via a drop-down box).
6
- Version: 1.63
7
  Author: David Gwyer
8
- Author URI: http://www.presscoders.com
9
  */
10
 
11
- /* Copyright 2009 David Gwyer (email : d.v.gwyer@presscoders.com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
@@ -26,61 +26,61 @@ Author URI: http://www.presscoders.com
26
  */
27
 
28
  /* @todo:
29
- - Redo Plugin screenshots.
30
- - Add text box that allows you to enter a comma separated list of custom post type names to exclude from the front end sitemap. Maybe only show this text box if the checkbox to show cpt is selected. For convenience, show a current list of cpt names that can be excluded.
31
- - Add option that if a page ID is excluded, it also excludes its children?
32
- - Get rid of query_posts().
33
- - Enable responsive wrapping so that if there is space multiple columns will span across the page and automatically wrap to the next line when not enough space.
34
- - Add archive pages to sitemap: http://wordpress.org/support/topic/include-archive-urls.
35
- - Be able to sort ascending/descending in addition to the sort drop down options for each list.
36
- - Add all Plugin options page in-line styles to external style sheet.
37
- - Options to display custom post types, with ability to show which custom post types to display or not display, and in what order?
38
- - Consider adding a drop down in Plugin options to show the page hierarchy as it appears in 'Pages' (i.e. the way it works now), or to show it via a defined custom menu hierarchy in Appearance -> Menus.
39
- - Add option to remove certain tags, categories, or posts.
40
- - Use the 'prepare' WP feature when querying the db directly.
41
- - Use translation functions _e(), __() etc. Add Plugin text domain too.
42
- - Show all the posts in each category not just the maximum allowed in Settings -> Reading.
43
- - Update Plugin description and other sections, as well as the images which are out of date (show the single column working on the sidebar).
44
- - Maybe support shortcode attributes so that users can specify to add custom behaviour for individual sitemaps if more than one is needed on a site. Any attributes would override global Plugin settings that affects all sitemaps by default.
45
- - Exclude certain posts and categories from showing, similar to how pages can be excluded. Later extend this to CPT posts and archives too.
46
- */
47
 
48
  /* wpss_ prefix is derived from [W]ord[P]ress [s]imple [s]itemap. */
49
- add_shortcode('simple-sitemap', 'wpss_gen');
50
 
51
- register_activation_hook(__FILE__, 'wpss_add_defaults');
52
- register_uninstall_hook(__FILE__, 'wpss_delete_plugin_options');
53
- add_action('admin_init', 'wpss_init' );
54
- add_action('admin_menu', 'wpss_add_options_page');
55
  add_filter( 'plugin_action_links', 'wpss_plugin_action_links', 10, 2 );
56
- add_filter('widget_text', 'do_shortcode'); // make sitemap shortcode work in text widgets
57
 
58
  /* Delete options table entries ONLY when plugin deactivated AND deleted. */
59
  function wpss_delete_plugin_options() {
60
- delete_option('wpss_options');
61
  }
62
 
63
  /* Define default option settings. */
64
  function wpss_add_defaults() {
65
 
66
- $tmp = get_option('wpss_options');
67
- if( ( (isset($tmp['chk_default_options_db']) && $tmp['chk_default_options_db']=='1')) || (!is_array($tmp)) ) {
68
- delete_option('wpss_options');
69
- $arr = array( "drp_pages_default" => "post_title",
70
- "drp_posts_default" => "title",
71
- "chk_default_options_db" => "0",
72
- "chk_show_pages" => "1",
73
- "chk_show_cpts" => "1",
74
- "chk_show_posts" => "1",
75
- "txt_page_ids" => ""
76
  );
77
  update_option( 'wpss_options', $arr );
78
  }
79
 
80
  // Make sure that something displays on the front end (i.e. the post, page, CPT check boxes are not all off)
81
- $tmp1 = get_option('wpss_options');
82
- if( isset($tmp1) && is_array($tmp1) ) {
83
- if( !( isset($tmp1['chk_show_posts']) && $tmp1['chk_show_posts'] ) && !( isset($tmp1['chk_show_pages']) && $tmp1['chk_show_pages'] ) ) {
84
  // show pages and posts if nothing selected
85
  $tmp1['chk_show_pages'] = "1";
86
  $tmp1['chk_show_posts'] = "1";
@@ -91,14 +91,14 @@ function wpss_add_defaults() {
91
  }
92
 
93
  /* Init plugin options to white list our options. */
94
- function wpss_init(){
95
 
96
  register_setting( 'wpss_plugin_options', 'wpss_options', 'wpss_validate_options' );
97
  }
98
 
99
  /* Add menu page. */
100
  function wpss_add_options_page() {
101
- add_options_page('Simple Sitemap Options Page', 'Simple Sitemap', 'manage_options', __FILE__, 'wpss_render_form');
102
  }
103
 
104
  /* Draw the menu page itself. */
@@ -107,18 +107,20 @@ function wpss_render_form() {
107
  <div class="wrap">
108
  <h2>Simple Sitemap Options</h2>
109
 
110
- <div style="background:#eee;border: 1px dashed #ccc;font-size: 13px;margin: 20px 0 10px 0;padding: 5px 0 5px 8px;">To display the Simple Sitemap on a post, page, or sidebar (via a Text widget), enter the following <a href="http://codex.wordpress.org/Shortcode_API" target="_blank">shortcode</a>: <b>[simple-sitemap]</b></div>
 
 
111
  <form method="post" action="options.php">
112
- <?php settings_fields('wpss_plugin_options'); ?>
113
- <?php $options = get_option('wpss_options'); ?>
114
  <table class="form-table">
115
  <tr>
116
  <th scope="row">Pages Default List Type</th>
117
  <td>
118
  <select style="width:90px;" name='wpss_options[drp_pages_default]'>
119
- <option value='post_title' <?php selected('post_title', $options['drp_pages_default']); ?>>Title</option>
120
- <option value='post_date' <?php selected('post_date', $options['drp_pages_default']); ?>>Date</option>
121
- <option value='post_author' <?php selected('post_author', $options['drp_pages_default']); ?>>Author</option>
122
  </select>
123
  </td>
124
  </tr>
@@ -127,11 +129,11 @@ function wpss_render_form() {
127
  <th scope="row">Posts Default List Type</th>
128
  <td>
129
  <select style="width:90px;" name='wpss_options[drp_posts_default]'>
130
- <option value='title' <?php selected('title', $options['drp_posts_default']); ?>>Title</option>
131
- <option value='date' <?php selected('date', $options['drp_posts_default']); ?>>Date</option>
132
- <option value='author' <?php selected('author', $options['drp_posts_default']); ?>>Author</option>
133
- <option value='category' <?php selected('category', $options['drp_posts_default']); ?>>Category</option>
134
- <option value='tags' <?php selected('tags', $options['drp_posts_default']); ?>>Tags</option>
135
  </select>
136
  </td>
137
  </tr>
@@ -139,47 +141,76 @@ function wpss_render_form() {
139
  <tr>
140
  <th scope="row">Exclude Pages</th>
141
  <td>
142
- <input type="text" size="30" name="wpss_options[txt_page_ids]" value="<?php echo $options['txt_page_ids']; ?>" /><p class="description">Enter a comma separated list of Page ID's.</p>
 
 
143
  </td>
144
  </tr>
145
 
146
  <tr>
147
  <th scope="row">Show Pages</th>
148
  <td>
149
- <label><input name="wpss_options[chk_show_pages]" type="checkbox" value="1" <?php if (isset($options['chk_show_pages'])) { checked('1', $options['chk_show_pages']); } ?> /> Display pages on front end sitemap?</label>
 
 
150
  </td>
151
  </tr>
152
 
153
  <tr>
154
  <th scope="row">Show Posts</th>
155
  <td>
156
- <label><input name="wpss_options[chk_show_posts]" type="checkbox" value="1" <?php if (isset($options['chk_show_posts'])) { checked('1', $options['chk_show_posts']); } ?> /> Display posts on front end sitemap?</label>
 
 
157
  </td>
158
  </tr>
159
 
160
  <tr>
161
  <th scope="row">Show Custom Post Types</th>
162
  <td>
163
- <label><input name="wpss_options[chk_show_cpts]" type="checkbox" value="1" <?php if (isset($options['chk_show_cpts'])) { checked('1', $options['chk_show_cpts']); } ?> /> Display Custom Post Types on front end sitemap?</label>
 
 
164
  </td>
165
  </tr>
166
 
167
  <tr valign="top" style="border-top:#dddddd 1px solid;">
168
  <th scope="row">Database Options</th>
169
  <td>
170
- <label><input name="wpss_options[chk_default_options_db]" type="checkbox" value="1" <?php if (isset($options['chk_default_options_db'])) { checked('1', $options['chk_default_options_db']); } ?> /> Restore Plugin defaults upon deactivation/reactivation</label><p class="description">Only check this if you want to reset plugin settings upon reactivation</p>
 
 
 
 
171
  </td>
172
  </tr>
173
  </table>
174
  <p class="submit">
175
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
176
  </p>
177
  </form>
178
 
179
- <p>Note: This is a FREE Plugin. If you use it on your website <b>please</b> consider making a <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UUFZZU35RZPW8" target="_blank">donation</a> to support continued development.</p>
180
- <a href="http://www.twitter.com/dgwyer" title="Follow on Twitter" target="_blank"><img src="<?php echo plugins_url(); ?>/simple-sitemap/images/twitter.png" /></a>&nbsp;<input class="button" style="vertical-align:12px;" type="button" value="Visit Our Site" onClick="window.open('http://www.presscoders.com')"></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  </div>
182
- <?php
183
  }
184
 
185
  /* Shortcode function. */
@@ -187,116 +218,122 @@ function wpss_gen() {
187
 
188
  ob_start(); // start output caching (so that existing content in the [simple-sitemap] post doesn't get shoved to the bottom of the post
189
 
190
- $opt = get_option('wpss_options');
191
 
192
  // Page query args from Plugin options
193
- if($opt['drp_pages_default'] == "post_title") {
194
  $page_params = 'menu_order, post_title';
195
- }
196
- else if ($opt['drp_pages_default'] == "post_date") {
197
- $page_params = 'post_date';
198
- }
199
- else {
200
- $page_params = 'post_author';
201
  }
202
 
203
- $page_args = array( 'sort_column' => $page_params, 'title_li' => '');
204
- if( !empty( $opt['txt_page_ids'] ) ) $page_args['exclude'] = $opt['txt_page_ids'];
 
 
205
 
206
  // Post query args from Plugin options
207
- if($opt['drp_posts_default'] == "title") {
208
  $post_params = 'title';
209
- }
210
- else if ($opt['drp_posts_default'] == "date") {
211
- $post_params = 'date';
212
- }
213
- else if ($opt['drp_posts_default'] == "author") {
214
- $post_params = 'author';
215
- }
216
- else if ($opt['drp_posts_default'] == "category") {
217
- $post_params = 'category';
218
- }
219
- else {
220
- $post_params = 'tags';
 
 
221
  }
222
 
223
- $post_args = array( 'orderby' => $post_params, 'posts_per_page' => -1, 'order' => 'asc' );
224
 
225
- ?>
226
 
227
- <div class="ss_wrapper">
228
 
229
- <?php // RENDER SITEMAP PAGES ?>
230
 
231
- <?php if(isset($opt['chk_show_pages']) && $opt['chk_show_pages']) : ?>
232
 
233
  <div id="ss_pages">
234
 
235
  <h2 class='page_heading'>Pages</h2>
236
-
237
  <?php
238
- if(strpos($page_params, 'post_date') !== false) {
239
  echo '<ul class="page_item_list">';
240
- $page_args=array('sort_order' => 'desc', 'sort_column' => 'post_date', 'title_li' => '');
241
- if( !empty( $opt['txt_page_ids'] ) ) $page_args['exclude'] = $opt['txt_page_ids'];
242
- wp_list_pages($page_args); // show the sorted pages
 
 
243
  echo '</ul>';
244
- }
245
- elseif(strpos($page_params, 'post_author') !== false) {
246
  $authors = get_users(); //gets registered users
247
- foreach ($authors as $author) {
248
- $empty_page_args=array('echo' => 0, 'authors' => $author->ID, 'title_li' => '');
249
- $empty_test = wp_list_pages($empty_page_args); // test for authors with zero pages
250
  //echo '$empty_test = '.$empty_test;
251
-
252
- if($empty_test != null || $empty_test != "") {
253
  echo "<div class='page_author'>$author->display_name</div>";
254
  echo "<div class=\"ss_date_header\"><ul class=\"page_item_list\">";
255
- $page_args=array('authors' => $author->ID, 'title_li' => '');
256
- if( !empty( $opt['txt_page_ids'] ) ) $page_args['exclude'] = $opt['txt_page_ids'];
257
- wp_list_pages($page_args);
 
 
258
  echo "</ul></div>";
259
- }
260
- else {
261
  echo "<div class='page_author'>$author->display_name <span class=\"ss_sticky\">(no pages published)</span></div>";
262
  }
263
  } ?>
264
  <?php
265
- }
266
- else { /* default = title */
267
  echo '<ul class="page_item_list">';
268
- wp_list_pages($page_args); /* Show sorted pages with default $page_args. */
269
  echo '</ul>';
270
  }
271
  ?>
272
  </div><!--ss_pages -->
273
-
274
- <?php endif; ?>
275
 
276
 
277
- <?php // RENDER SITEMAP POSTS ?>
278
 
279
- <?php if(isset($opt['chk_show_posts']) && $opt['chk_show_posts']) : ?>
280
 
281
  <div id="ss_posts">
282
  <h2 class='post_heading'>Posts</h2>
283
 
284
  <?php
285
- if(strpos($post_params, 'category') !== false) {
286
  $categories = get_categories();
287
- foreach ($categories as $category) {
288
- $category_link = get_category_link($category->term_id);
289
- $cat_count = $category->category_count;
290
 
291
- echo '<div class="ss_cat_header"><a href="'.$category_link.'">'.ucwords($category->cat_name).'</a> ';
292
- query_posts('posts_per_page=-1&post_status=publish&cat='.$category->term_id); // show the sorted posts ?>
 
293
  <?php
294
- global $wp_query;
295
- echo '('.$wp_query->post_count.')</div>'; ?>
296
  <?php
297
- if (have_posts()) :
298
  echo '<div class="post_item_list"><ul class="post_item_list">';
299
- while (have_posts()) :
300
  the_post(); ?>
301
  <li class="post_item">
302
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
@@ -306,19 +343,19 @@ function wpss_gen() {
306
  endif;
307
  wp_reset_query();
308
  }
309
- }
310
- else if(strpos($post_params, 'author') !== false) {
311
  $authors = get_users(); //gets registered users
312
- foreach ($authors as $author) {
313
- echo '<a href="'.get_author_posts_url($author->ID).'">'.$author->display_name.'</a> ';
314
- query_posts('posts_per_page=-1&post_status=publish&author='.$author->ID); // show the sorted posts ?>
 
315
  <?php
316
- global $wp_query;
317
- echo '('.$wp_query->post_count.')'; ?>
318
  <?php
319
- if (have_posts()) :
320
  echo '<div class="post_item_list"><ul class="post_item_list">';
321
- while (have_posts()) :
322
  the_post(); ?>
323
  <li class="post_item">
324
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
@@ -328,20 +365,20 @@ function wpss_gen() {
328
  endif;
329
  wp_reset_query();
330
  }
331
- }
332
- else if(strpos($post_params, 'tags') !== false) {
333
  $post_tags = get_tags();
334
  echo '<div class="ss_tag_header">';
335
- foreach ($post_tags as $tag){
336
- $tag_link = get_tag_link($tag->term_id);
337
  echo "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
338
  echo "{$tag->name}</a> ($tag->count)";
339
 
340
- query_posts('posts_per_page=-1&post_status=publish&tag='.$tag->slug); // show posts ?>
 
341
  <?php
342
- if (have_posts()) :
343
  echo '<div class="post_item_list"><ul class="post_item_list">';
344
- while (have_posts()) :
345
  the_post(); ?>
346
  <li class="post_item">
347
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
@@ -352,44 +389,47 @@ function wpss_gen() {
352
  wp_reset_query();
353
  }
354
  echo '</div>';
355
- }
356
- else if(strpos($post_params, 'date') !== false) {
357
- ?><div class="ss_date_header">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  <?php
359
- global $wpdb;
360
- $months = $wpdb->get_results($wpdb->prepare( "SELECT DISTINCT MONTH(post_date) AS month , YEAR(post_date) AS year FROM $wpdb->posts WHERE post_status = %s and post_date <= now( ) and post_type = %s GROUP BY month, year ORDER BY post_date DESC", 'publish', 'post' ));
361
- foreach($months as $curr_month){
362
- query_posts('posts_per_page=-1&post_status=publish&monthnum='.$curr_month->month.'&year='.$curr_month->year); // show posts ?>
363
- <?php
364
- global $wp_query;
365
- echo "<a href=\"";
366
- echo get_month_link($curr_month->year, $curr_month->month);
367
- echo '">'.date( 'F', mktime(0, 0, 0, $curr_month->month) ).' '.$curr_month->year.'</a> ('.$wp_query->post_count.')'; ?>
368
- <?php
369
- if (have_posts()) :
370
- echo '<div class="post_item_list"><ul class="post_item_list">';
371
- while (have_posts()) :
372
- the_post(); ?>
373
- <li class="post_item">
374
- <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
375
- </li>
376
- <?php endwhile;
377
- echo '</ul></div>';
378
- endif;
379
- wp_reset_query();
380
- } ?>
381
- </div>
382
- <?php
383
- }
384
- else { /* default = title */
385
- ?>
386
- <?php query_posts($post_args); /* Show sorted posts with default $post_args. */
387
- if (have_posts()) :
388
  echo '<ul class="post_item_list">';
389
- while (have_posts()) :
390
  the_post();
391
- $sticky="";
392
- if(is_sticky(get_the_ID())) { $sticky=" (sticky post)"; } ?>
 
 
393
  <li class="post_item">
394
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
395
  <?php if ( $sticky == ' (sticky post)' ) : ?>
@@ -400,53 +440,54 @@ function wpss_gen() {
400
  echo '</ul>';
401
  endif;
402
  wp_reset_query();
 
403
  }
404
  ?>
405
  </div><!--ss_posts-->
406
 
407
- <?php endif; ?>
408
 
409
 
410
- <?php // RENDER SITEMAP CUSTOM POST TYPES ?>
411
 
412
- <?php
413
- $args = array( 'public' => true, '_builtin' => false );
414
- $custom_post_types = get_post_types( $args, 'objects' );
415
 
416
- foreach ( $custom_post_types as $post_type ) :
417
  ?>
418
 
419
- <?php if(isset($opt['chk_show_cpts']) && $opt['chk_show_cpts']) : ?>
420
 
421
- <div id="ss_cpt">
422
 
423
- <h2 class='cpt_heading'><?php echo $post_type->label; ?></h2>
424
-
425
- <?php
426
 
427
- $cpt_posts = get_posts( 'post_type='.$post_type->name.'&posts_per_page=-1' );
428
 
429
- if( $cpt_posts ) : ?>
430
- <ul class="cpt_item_list">
431
- <?php foreach( $cpt_posts as $cpt_post ) : ?>
432
  <?php $cpt_link = get_post_permalink( $cpt_post->ID ); ?>
433
  <li><a href="<?php echo $cpt_link; ?>"> <?php echo $cpt_post->post_title; ?></a></li>
434
  <?php endforeach; ?>
435
- </ul>
436
- <?php endif; ?>
437
- </div><!--ss_cpt -->
438
-
439
  <?php endif; ?>
 
440
 
441
- <?php endforeach ?>
442
 
443
- </div>
444
- <?php
 
 
445
 
446
- $output = ob_get_contents();;
447
- ob_end_clean();
448
 
449
- return $output;
450
 
451
  }
452
 
@@ -454,7 +495,7 @@ return $output;
454
  function wpss_plugin_action_links( $links, $file ) {
455
 
456
  if ( $file == plugin_basename( __FILE__ ) ) {
457
- $posk_links = '<a href="'.get_admin_url().'options-general.php?page=simple-sitemap/simple-sitemap.php">'.__('Settings').'</a>';
458
  // make the 'Settings' link appear first
459
  array_unshift( $links, $posk_links );
460
  }
@@ -463,7 +504,7 @@ function wpss_plugin_action_links( $links, $file ) {
463
  }
464
 
465
  /* Sanitize and validate input. Accepts an array, return a sanitized array. */
466
- function wpss_validate_options($input) {
467
  // Strip html from textboxes
468
  // e.g. $input['textbox'] = wp_filter_nohtml_kses($input['textbox']);
469
 
1
  <?php
2
  /*
3
  Plugin Name: Simple Sitemap
4
+ Plugin URI: http://wordpress.org/plugins/simple-sitemap/
5
  Description: HTML sitemap to display content as a single linked list of posts and pages, or as groups sorted by taxonomy (via a drop-down box).
6
+ Version: 1.64
7
  Author: David Gwyer
8
+ Author URI: http://www.wpgothemes.com
9
  */
10
 
11
+ /* Copyright 2009 David Gwyer (email : david@wpgothemes.com)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
26
  */
27
 
28
  /* @todo:
29
+ * - Redo Plugin screenshots.
30
+ * - Add text box that allows you to enter a comma separated list of custom post type names to exclude from the front end sitemap. Maybe only show this text box if the checkbox to show cpt is selected. For convenience, show a current list of cpt names that can be excluded.
31
+ * - Add option that if a page ID is excluded, it also excludes its children?
32
+ * - Get rid of query_posts().
33
+ * - Enable responsive wrapping so that if there is space multiple columns will span across the page and automatically wrap to the next line when not enough space.
34
+ * - Add archive pages to sitemap: http://wordpress.org/support/topic/include-archive-urls.
35
+ * - Be able to sort ascending/descending in addition to the sort drop down options for each list.
36
+ * - Add all Plugin options page in-line styles to external style sheet.
37
+ * - Options to display custom post types, with ability to show which custom post types to display or not display, and in what order?
38
+ * - Consider adding a drop down in Plugin options to show the page hierarchy as it appears in 'Pages' (i.e. the way it works now), or to show it via a defined custom menu hierarchy in Appearance -> Menus.
39
+ * - Add option to remove certain tags, categories, or posts.
40
+ * - Use the 'prepare' WP feature when querying the db directly.
41
+ * - Use translation functions _e(), __() etc. Add Plugin text domain too.
42
+ * - Show all the posts in each category not just the maximum allowed in Settings -> Reading.
43
+ * - Update Plugin description and other sections, as well as the images which are out of date (show the single column working on the sidebar).
44
+ * - Maybe support shortcode attributes so that users can specify to add custom behaviour for individual sitemaps if more than one is needed on a site. Any attributes would override global Plugin settings that affects all sitemaps by default.
45
+ * - Exclude certain posts and categories from showing, similar to how pages can be excluded. Later extend this to CPT posts and archives too.
46
+ */
47
 
48
  /* wpss_ prefix is derived from [W]ord[P]ress [s]imple [s]itemap. */
49
+ add_shortcode( 'simple-sitemap', 'wpss_gen' );
50
 
51
+ register_activation_hook( __FILE__, 'wpss_add_defaults' );
52
+ register_uninstall_hook( __FILE__, 'wpss_delete_plugin_options' );
53
+ add_action( 'admin_init', 'wpss_init' );
54
+ add_action( 'admin_menu', 'wpss_add_options_page' );
55
  add_filter( 'plugin_action_links', 'wpss_plugin_action_links', 10, 2 );
56
+ add_filter( 'widget_text', 'do_shortcode' ); // make sitemap shortcode work in text widgets
57
 
58
  /* Delete options table entries ONLY when plugin deactivated AND deleted. */
59
  function wpss_delete_plugin_options() {
60
+ delete_option( 'wpss_options' );
61
  }
62
 
63
  /* Define default option settings. */
64
  function wpss_add_defaults() {
65
 
66
+ $tmp = get_option( 'wpss_options' );
67
+ if ( ( ( isset( $tmp['chk_default_options_db'] ) && $tmp['chk_default_options_db'] == '1' ) ) || ( ! is_array( $tmp ) ) ) {
68
+ delete_option( 'wpss_options' );
69
+ $arr = array( "drp_pages_default" => "post_title",
70
+ "drp_posts_default" => "title",
71
+ "chk_default_options_db" => "0",
72
+ "chk_show_pages" => "1",
73
+ "chk_show_cpts" => "1",
74
+ "chk_show_posts" => "1",
75
+ "txt_page_ids" => ""
76
  );
77
  update_option( 'wpss_options', $arr );
78
  }
79
 
80
  // Make sure that something displays on the front end (i.e. the post, page, CPT check boxes are not all off)
81
+ $tmp1 = get_option( 'wpss_options' );
82
+ if ( isset( $tmp1 ) && is_array( $tmp1 ) ) {
83
+ if ( ! ( isset( $tmp1['chk_show_posts'] ) && $tmp1['chk_show_posts'] ) && ! ( isset( $tmp1['chk_show_pages'] ) && $tmp1['chk_show_pages'] ) ) {
84
  // show pages and posts if nothing selected
85
  $tmp1['chk_show_pages'] = "1";
86
  $tmp1['chk_show_posts'] = "1";
91
  }
92
 
93
  /* Init plugin options to white list our options. */
94
+ function wpss_init() {
95
 
96
  register_setting( 'wpss_plugin_options', 'wpss_options', 'wpss_validate_options' );
97
  }
98
 
99
  /* Add menu page. */
100
  function wpss_add_options_page() {
101
+ add_options_page( 'Simple Sitemap Options Page', 'Simple Sitemap', 'manage_options', __FILE__, 'wpss_render_form' );
102
  }
103
 
104
  /* Draw the menu page itself. */
107
  <div class="wrap">
108
  <h2>Simple Sitemap Options</h2>
109
 
110
+ <div style="background:#eee;border: 1px dashed #ccc;font-size: 13px;margin: 20px 0 10px 0;padding: 5px 0 5px 8px;">To display the Simple Sitemap on a post, page, or sidebar (via a Text widget), enter the following
111
+ <a href="http://codex.wordpress.org/Shortcode_API" target="_blank">shortcode</a>: <b>[simple-sitemap]</b>
112
+ </div>
113
  <form method="post" action="options.php">
114
+ <?php settings_fields( 'wpss_plugin_options' ); ?>
115
+ <?php $options = get_option( 'wpss_options' ); ?>
116
  <table class="form-table">
117
  <tr>
118
  <th scope="row">Pages Default List Type</th>
119
  <td>
120
  <select style="width:90px;" name='wpss_options[drp_pages_default]'>
121
+ <option value='post_title' <?php selected( 'post_title', $options['drp_pages_default'] ); ?>>Title</option>
122
+ <option value='post_date' <?php selected( 'post_date', $options['drp_pages_default'] ); ?>>Date</option>
123
+ <option value='post_author' <?php selected( 'post_author', $options['drp_pages_default'] ); ?>>Author</option>
124
  </select>
125
  </td>
126
  </tr>
129
  <th scope="row">Posts Default List Type</th>
130
  <td>
131
  <select style="width:90px;" name='wpss_options[drp_posts_default]'>
132
+ <option value='title' <?php selected( 'title', $options['drp_posts_default'] ); ?>>Title</option>
133
+ <option value='date' <?php selected( 'date', $options['drp_posts_default'] ); ?>>Date</option>
134
+ <option value='author' <?php selected( 'author', $options['drp_posts_default'] ); ?>>Author</option>
135
+ <option value='category' <?php selected( 'category', $options['drp_posts_default'] ); ?>>Category</option>
136
+ <option value='tags' <?php selected( 'tags', $options['drp_posts_default'] ); ?>>Tags</option>
137
  </select>
138
  </td>
139
  </tr>
141
  <tr>
142
  <th scope="row">Exclude Pages</th>
143
  <td>
144
+ <input type="text" size="30" name="wpss_options[txt_page_ids]" value="<?php echo $options['txt_page_ids']; ?>" />
145
+
146
+ <p class="description">Enter a comma separated list of Page ID's.</p>
147
  </td>
148
  </tr>
149
 
150
  <tr>
151
  <th scope="row">Show Pages</th>
152
  <td>
153
+ <label><input name="wpss_options[chk_show_pages]" type="checkbox" value="1" <?php if ( isset( $options['chk_show_pages'] ) ) {
154
+ checked( '1', $options['chk_show_pages'] );
155
+ } ?> /> Display pages on front end sitemap?</label>
156
  </td>
157
  </tr>
158
 
159
  <tr>
160
  <th scope="row">Show Posts</th>
161
  <td>
162
+ <label><input name="wpss_options[chk_show_posts]" type="checkbox" value="1" <?php if ( isset( $options['chk_show_posts'] ) ) {
163
+ checked( '1', $options['chk_show_posts'] );
164
+ } ?> /> Display posts on front end sitemap?</label>
165
  </td>
166
  </tr>
167
 
168
  <tr>
169
  <th scope="row">Show Custom Post Types</th>
170
  <td>
171
+ <label><input name="wpss_options[chk_show_cpts]" type="checkbox" value="1" <?php if ( isset( $options['chk_show_cpts'] ) ) {
172
+ checked( '1', $options['chk_show_cpts'] );
173
+ } ?> /> Display Custom Post Types on front end sitemap?</label>
174
  </td>
175
  </tr>
176
 
177
  <tr valign="top" style="border-top:#dddddd 1px solid;">
178
  <th scope="row">Database Options</th>
179
  <td>
180
+ <label><input name="wpss_options[chk_default_options_db]" type="checkbox" value="1" <?php if ( isset( $options['chk_default_options_db'] ) ) {
181
+ checked( '1', $options['chk_default_options_db'] );
182
+ } ?> /> Restore Plugin defaults upon deactivation/reactivation</label>
183
+
184
+ <p class="description">Only check this if you want to reset plugin settings upon reactivation</p>
185
  </td>
186
  </tr>
187
  </table>
188
  <p class="submit">
189
+ <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" />
190
  </p>
191
  </form>
192
 
193
+ <?php
194
+
195
+ $discount_date = "14th August 2014";
196
+ if( strtotime($discount_date) > strtotime('now') ) {
197
+ echo '<p style="background: #eee;border: 1px dashed #ccc;font-size: 13px;margin: 0 0 10px 0;padding: 5px 0 5px 8px;">For a limited time only! <strong>Get 50% OFF</strong> the price of our brand new mobile ready, fully responsive <a href="http://www.wpgothemes.com/themes/minn/" target="_blank"><strong>Minn WordPress theme</strong></a>. Simply enter the following code at checkout: <code>MINN50OFF</code></p>';
198
+ } else {
199
+ echo '<p style="background: #eee;border: 1px dashed #ccc;font-size: 13px;margin: 0 0 10px 0;padding: 5px 0 5px 8px;">As a user of our free plugins here\'s a bonus just for you! <strong>Get 30% OFF</strong> the price of our brand new mobile ready, fully responsive <a href="http://www.wpgothemes.com/themes/minn/" target="_blank"><strong>Minn WordPress theme</strong></a>. Simply enter the following code at checkout: <code>WPGO30OFF</code></p>';
200
+ }
201
+
202
+ ?>
203
+
204
+ <div style="clear:both;">
205
+ <p>
206
+ <a href="http://www.twitter.com/dgwyer" title="Follow me Twitter!" target="_blank"><img src="<?php echo plugins_url(); ?>/simple-sitemap/images/twitter.png" /></a>&nbsp;&nbsp;
207
+ <input class="button" style="vertical-align:12px;" type="button" value="Visit Our NEW Site!" onClick="window.open('http://www.wpgothemes.com')">
208
+ <input class="button" style="vertical-align:12px;" type="button" value="Minn, Our Latest Theme" onClick="window.open('http://www.wpgothemes.com/themes/minn')">
209
+ </p>
210
+ </div>
211
+
212
  </div>
213
+ <?php
214
  }
215
 
216
  /* Shortcode function. */
218
 
219
  ob_start(); // start output caching (so that existing content in the [simple-sitemap] post doesn't get shoved to the bottom of the post
220
 
221
+ $opt = get_option( 'wpss_options' );
222
 
223
  // Page query args from Plugin options
224
+ if ( $opt['drp_pages_default'] == "post_title" ) {
225
  $page_params = 'menu_order, post_title';
226
+ } else {
227
+ if ( $opt['drp_pages_default'] == "post_date" ) {
228
+ $page_params = 'post_date';
229
+ } else {
230
+ $page_params = 'post_author';
231
+ }
232
  }
233
 
234
+ $page_args = array( 'sort_column' => $page_params, 'title_li' => '' );
235
+ if ( ! empty( $opt['txt_page_ids'] ) ) {
236
+ $page_args['exclude'] = $opt['txt_page_ids'];
237
+ }
238
 
239
  // Post query args from Plugin options
240
+ if ( $opt['drp_posts_default'] == "title" ) {
241
  $post_params = 'title';
242
+ } else {
243
+ if ( $opt['drp_posts_default'] == "date" ) {
244
+ $post_params = 'date';
245
+ } else {
246
+ if ( $opt['drp_posts_default'] == "author" ) {
247
+ $post_params = 'author';
248
+ } else {
249
+ if ( $opt['drp_posts_default'] == "category" ) {
250
+ $post_params = 'category';
251
+ } else {
252
+ $post_params = 'tags';
253
+ }
254
+ }
255
+ }
256
  }
257
 
258
+ $post_args = array( 'orderby' => $post_params, 'posts_per_page' => - 1, 'order' => 'asc' );
259
 
260
+ ?>
261
 
262
+ <div class="ss_wrapper">
263
 
264
+ <?php // RENDER SITEMAP PAGES ?>
265
 
266
+ <?php if ( isset( $opt['chk_show_pages'] ) && $opt['chk_show_pages'] ) : ?>
267
 
268
  <div id="ss_pages">
269
 
270
  <h2 class='page_heading'>Pages</h2>
271
+
272
  <?php
273
+ if ( strpos( $page_params, 'post_date' ) !== false ) {
274
  echo '<ul class="page_item_list">';
275
+ $page_args = array( 'sort_order' => 'desc', 'sort_column' => 'post_date', 'title_li' => '' );
276
+ if ( ! empty( $opt['txt_page_ids'] ) ) {
277
+ $page_args['exclude'] = $opt['txt_page_ids'];
278
+ }
279
+ wp_list_pages( $page_args ); // show the sorted pages
280
  echo '</ul>';
281
+ } elseif ( strpos( $page_params, 'post_author' ) !== false ) {
 
282
  $authors = get_users(); //gets registered users
283
+ foreach ( $authors as $author ) {
284
+ $empty_page_args = array( 'echo' => 0, 'authors' => $author->ID, 'title_li' => '' );
285
+ $empty_test = wp_list_pages( $empty_page_args ); // test for authors with zero pages
286
  //echo '$empty_test = '.$empty_test;
287
+
288
+ if ( $empty_test != null || $empty_test != "" ) {
289
  echo "<div class='page_author'>$author->display_name</div>";
290
  echo "<div class=\"ss_date_header\"><ul class=\"page_item_list\">";
291
+ $page_args = array( 'authors' => $author->ID, 'title_li' => '' );
292
+ if ( ! empty( $opt['txt_page_ids'] ) ) {
293
+ $page_args['exclude'] = $opt['txt_page_ids'];
294
+ }
295
+ wp_list_pages( $page_args );
296
  echo "</ul></div>";
297
+ } else {
 
298
  echo "<div class='page_author'>$author->display_name <span class=\"ss_sticky\">(no pages published)</span></div>";
299
  }
300
  } ?>
301
  <?php
302
+ } else { /* default = title */
 
303
  echo '<ul class="page_item_list">';
304
+ wp_list_pages( $page_args ); /* Show sorted pages with default $page_args. */
305
  echo '</ul>';
306
  }
307
  ?>
308
  </div><!--ss_pages -->
309
+
310
+ <?php endif; ?>
311
 
312
 
313
+ <?php // RENDER SITEMAP POSTS ?>
314
 
315
+ <?php if ( isset( $opt['chk_show_posts'] ) && $opt['chk_show_posts'] ) : ?>
316
 
317
  <div id="ss_posts">
318
  <h2 class='post_heading'>Posts</h2>
319
 
320
  <?php
321
+ if ( strpos( $post_params, 'category' ) !== false ) {
322
  $categories = get_categories();
323
+ foreach ( $categories as $category ) {
324
+ $category_link = get_category_link( $category->term_id );
325
+ $cat_count = $category->category_count;
326
 
327
+ echo '<div class="ss_cat_header"><a href="' . $category_link . '">' . ucwords( $category->cat_name ) . '</a> ';
328
+ query_posts( 'posts_per_page=-1&post_status=publish&cat=' . $category->term_id ); // show the sorted posts
329
+ ?>
330
  <?php
331
+ global $wp_query;
332
+ echo '(' . $wp_query->post_count . ')</div>'; ?>
333
  <?php
334
+ if ( have_posts() ) :
335
  echo '<div class="post_item_list"><ul class="post_item_list">';
336
+ while ( have_posts() ) :
337
  the_post(); ?>
338
  <li class="post_item">
339
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
343
  endif;
344
  wp_reset_query();
345
  }
346
+ } else if ( strpos( $post_params, 'author' ) !== false ) {
 
347
  $authors = get_users(); //gets registered users
348
+ foreach ( $authors as $author ) {
349
+ echo '<a href="' . get_author_posts_url( $author->ID ) . '">' . $author->display_name . '</a> ';
350
+ query_posts( 'posts_per_page=-1&post_status=publish&author=' . $author->ID ); // show the sorted posts
351
+ ?>
352
  <?php
353
+ global $wp_query;
354
+ echo '(' . $wp_query->post_count . ')'; ?>
355
  <?php
356
+ if ( have_posts() ) :
357
  echo '<div class="post_item_list"><ul class="post_item_list">';
358
+ while ( have_posts() ) :
359
  the_post(); ?>
360
  <li class="post_item">
361
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
365
  endif;
366
  wp_reset_query();
367
  }
368
+ } else if ( strpos( $post_params, 'tags' ) !== false ) {
 
369
  $post_tags = get_tags();
370
  echo '<div class="ss_tag_header">';
371
+ foreach ( $post_tags as $tag ) {
372
+ $tag_link = get_tag_link( $tag->term_id );
373
  echo "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
374
  echo "{$tag->name}</a> ($tag->count)";
375
 
376
+ query_posts( 'posts_per_page=-1&post_status=publish&tag=' . $tag->slug ); // show posts
377
+ ?>
378
  <?php
379
+ if ( have_posts() ) :
380
  echo '<div class="post_item_list"><ul class="post_item_list">';
381
+ while ( have_posts() ) :
382
  the_post(); ?>
383
  <li class="post_item">
384
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
389
  wp_reset_query();
390
  }
391
  echo '</div>';
392
+ } else {
393
+ if ( strpos( $post_params, 'date' ) !== false ) {
394
+ ?>
395
+ <div class="ss_date_header">
396
+ <?php
397
+ global $wpdb;
398
+ $months = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT MONTH(post_date) AS month , YEAR(post_date) AS year FROM $wpdb->posts WHERE post_status = %s and post_date <= now( ) and post_type = %s GROUP BY month, year ORDER BY post_date DESC", 'publish', 'post' ) );
399
+ foreach ( $months as $curr_month ) {
400
+ query_posts( 'posts_per_page=-1&post_status=publish&monthnum=' . $curr_month->month . '&year=' . $curr_month->year ); // show posts
401
+ ?>
402
+ <?php
403
+ global $wp_query;
404
+ echo "<a href=\"";
405
+ echo get_month_link( $curr_month->year, $curr_month->month );
406
+ echo '">' . date( 'F', mktime( 0, 0, 0, $curr_month->month ) ) . ' ' . $curr_month->year . '</a> (' . $wp_query->post_count . ')'; ?>
407
+ <?php
408
+ if ( have_posts() ) :
409
+ echo '<div class="post_item_list"><ul class="post_item_list">';
410
+ while ( have_posts() ) :
411
+ the_post(); ?>
412
+ <li class="post_item">
413
+ <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
414
+ </li>
415
+ <?php endwhile;
416
+ echo '</ul></div>';
417
+ endif;
418
+ wp_reset_query();
419
+ } ?>
420
+ </div>
421
  <?php
422
+ } else { /* default = title */
423
+ ?>
424
+ <?php query_posts( $post_args ); /* Show sorted posts with default $post_args. */
425
+ if ( have_posts() ) :
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  echo '<ul class="post_item_list">';
427
+ while ( have_posts() ) :
428
  the_post();
429
+ $sticky = "";
430
+ if ( is_sticky( get_the_ID() ) ) {
431
+ $sticky = " (sticky post)";
432
+ } ?>
433
  <li class="post_item">
434
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
435
  <?php if ( $sticky == ' (sticky post)' ) : ?>
440
  echo '</ul>';
441
  endif;
442
  wp_reset_query();
443
+ }
444
  }
445
  ?>
446
  </div><!--ss_posts-->
447
 
448
+ <?php endif; ?>
449
 
450
 
451
+ <?php // RENDER SITEMAP CUSTOM POST TYPES ?>
452
 
453
+ <?php
454
+ $args = array( 'public' => true, '_builtin' => false );
455
+ $custom_post_types = get_post_types( $args, 'objects' );
456
 
457
+ foreach ( $custom_post_types as $post_type ) :
458
  ?>
459
 
460
+ <?php if ( isset( $opt['chk_show_cpts'] ) && $opt['chk_show_cpts'] ) : ?>
461
 
462
+ <div id="ss_cpt">
463
 
464
+ <h2 class='cpt_heading'><?php echo $post_type->label; ?></h2>
465
+
466
+ <?php
467
 
468
+ $cpt_posts = get_posts( 'post_type=' . $post_type->name . '&posts_per_page=-1' );
469
 
470
+ if ( $cpt_posts ) : ?>
471
+ <ul class="cpt_item_list">
472
+ <?php foreach ( $cpt_posts as $cpt_post ) : ?>
473
  <?php $cpt_link = get_post_permalink( $cpt_post->ID ); ?>
474
  <li><a href="<?php echo $cpt_link; ?>"> <?php echo $cpt_post->post_title; ?></a></li>
475
  <?php endforeach; ?>
476
+ </ul>
 
 
 
477
  <?php endif; ?>
478
+ </div><!--ss_cpt -->
479
 
480
+ <?php endif; ?>
481
 
482
+ <?php endforeach ?>
483
+
484
+ </div>
485
+ <?php
486
 
487
+ $output = ob_get_contents();;
488
+ ob_end_clean();
489
 
490
+ return $output;
491
 
492
  }
493
 
495
  function wpss_plugin_action_links( $links, $file ) {
496
 
497
  if ( $file == plugin_basename( __FILE__ ) ) {
498
+ $posk_links = '<a href="' . get_admin_url() . 'options-general.php?page=simple-sitemap/simple-sitemap.php">' . __( 'Settings' ) . '</a>';
499
  // make the 'Settings' link appear first
500
  array_unshift( $links, $posk_links );
501
  }
504
  }
505
 
506
  /* Sanitize and validate input. Accepts an array, return a sanitized array. */
507
+ function wpss_validate_options( $input ) {
508
  // Strip html from textboxes
509
  // e.g. $input['textbox'] = wp_filter_nohtml_kses($input['textbox']);
510