XML Sitemap & Google News feeds - Version 3.7.4

Version Description

  • switch from add_feed (on init) to the do_feed_$feed hook
  • BUGFIX: is_404() condition TRUE and Response Header 404 on sites without posts
  • BUGFIX: is_feed() condition FALSE after custom query_posts
  • BUGFIX: no lastmod on home url when only pages on a site
  • BUGFIX: stylesheet url wrong when WP installed in a subdir
Download this release

Release Info

Developer RavanH
Plugin Icon 128x128 XML Sitemap & Google News feeds
Version 3.7.4
Comparing to
See all releases

Code changes from version 3.7 to 3.7.4

Files changed (7) hide show
  1. feed-sitemap.php +44 -36
  2. readme.txt +44 -20
  3. screenshot-1.png +0 -0
  4. screenshot-2.png +0 -0
  5. sitemap.xsl.php +1 -1
  6. sitemapxml.gif +0 -0
  7. xml-sitemap.php +231 -31
feed-sitemap.php CHANGED
@@ -1,9 +1,22 @@
1
  <?php
2
- /* ---------------------------
3
- XML Sitemap Feed Template
4
- --------------------------- */
 
 
5
 
6
- // presets are changable; please read comments.
 
 
 
 
 
 
 
 
 
 
 
7
  $max_priority = 1.0; // Maximum priority value for any URL in the sitemap; set to any other value between 0 and 1.
8
  $min_priority = 0; // Minimum priority value for any URL in the sitemap; set to any other value between 0 and 1.
9
  // NOTE: Changing these values will influence each URL's priority. Priority values are taken by
@@ -12,34 +25,35 @@ $min_priority = 0; // Minimum priority value for any URL in the sitemap; set to
12
  $frontpage_priority = 1.0; // Your front page priority, usually the same as max priority but if you have any reason
13
  // to change it, please be my guest; set to any other value between 0 and 1.
14
 
15
- $maxURLS = -1; // When running into server memory problems, seeing a message like:
16
- // "Fatal error: Allowed memory size of xxx bytes exhausted..."
17
- // You might want to try setting the maxURLS value to 1000 and, if that works
18
- // and if necessery, increment the value by 1000 until the sitemap lists all
19
- // the posts.
20
  $level_weight = 0.1; // Makes a sub-page loose 10% for each level; set to any other value between 0 and 1.
21
  $month_weight = 0.1; // Fall-back value normally ignored by automatic priority calculation, which
22
  // makes a post loose 10% of priority monthly; set to any other value between 0 and 1.
23
 
24
  // editing below here is not advised!
25
 
26
- // change the main query
27
  query_posts( array(
28
- 'posts_per_page' => $maxURLS,
29
  'post_type' => 'any',
30
  'post_status' => 'publish',
31
- 'caller_get_posts' => '1'
32
- )
 
33
  );
34
 
 
 
 
 
 
35
  // setup site variables
36
  $_post_count = wp_count_posts('post');
37
  $_page_count = wp_count_posts('page');
38
  $_totalcommentcount = wp_count_comments();
39
 
40
- $lastpostmodified_gmt = get_lastpostmodified('GMT'); // last posts modified date
41
- $lastpostmodified = mysql2date('U',$lastpostmodified_gmt); // last posts modified date in Unix seconds
42
- $firstpostmodified = mysql2date('U',get_firstpostmodified('GMT')); // get_firstpostmodified() function defined in xml-sitemap.php !
43
 
44
  // calculated presets
45
  if ($_totalcommentcount->approved > 0)
@@ -48,42 +62,35 @@ else
48
  $comment_weight = 0;
49
 
50
  if ($_post_count->publish > $_page_count->publish) { // site emphasis on posts
51
- $post_priority = 0.8;
52
- $page_priority = 0.4;
53
  } else { // site emphasis on pages
54
  $post_priority = 0.4;
55
  $page_priority = 0.8;
56
  }
57
 
58
- if ( $lastpostmodified > $firstpostmodified ) // valid blog age found ?
59
- $age_weight = ($post_priority - $min_priority) / ($lastpostmodified - $firstpostmodified); // calculate relative age weight
60
  else
61
  $age_weight = $month_weight / 2629744 ; // else just do 10% per month (that's a month in seconds)
62
 
63
- // start the xml output
64
- header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
65
- echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?>
66
- <?xml-stylesheet type="text/xsl" href="'.get_option('home').'/'.str_replace(ABSPATH,"", XMLSF_PLUGIN_DIR).'/sitemap.xsl.php?v='.XMLSF_VERSION.'"?>
67
- <!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->
68
- <!-- generator="XML Sitemap Feed plugin for WordPress" -->
69
- <!-- generator-url="http://4visions.nl/en/index.php?section=57" -->
70
- <!-- generator-version="'.XMLSF_VERSION.'" -->
71
- '; ?>
72
  <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
73
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
74
  xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
75
  <url>
76
  <loc><?php bloginfo_rss('url') ?>/</loc>
77
- <lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $lastpostmodified_gmt, false); ?></lastmod>
78
  <changefreq>daily</changefreq>
79
  <priority>1.0</priority>
80
  </url>
81
  <?php
82
- // prepare counter to limit the number of URLs to the absolute max of 50.000
83
- $counter = 1;
84
-
85
  // and loop away!
86
- if ( have_posts() ) : while ( have_posts() && $counter < 50000 ) : the_post();
87
 
88
  $thispostmodified_gmt = $post->post_modified_gmt; // post GMT timestamp
89
  $thispostmodified = mysql2date('U',$thispostmodified_gmt); // post Unix timestamp
@@ -120,7 +127,7 @@ if ( have_posts() ) : while ( have_posts() && $counter < 50000 ) : the_post();
120
  $offset = (($post->comment_count - $average_commentcount) * $comment_weight) - (count($ancestors) * $level_weight);
121
  $priority = $page_priority + $offset;
122
  } else {
123
- $offset = (($post->comment_count - $average_commentcount) * $comment_weight) - (($lastpostmodified - $thispostmodified) * $age_weight);
124
  $priority = $post_priority + $offset;
125
  }
126
  // trim priority
@@ -144,5 +151,6 @@ if ( have_posts() ) : while ( have_posts() && $counter < 50000 ) : the_post();
144
  <?php
145
  $counter++;
146
 
147
- endwhile; endif; ?>
 
148
  </urlset>
1
  <?php
2
+ /**
3
+ * XML Sitemap Feed Template for displaying an XML Sitemap feed.
4
+ *
5
+ * @package XML Sitemap Feed plugin for WordPress
6
+ */
7
 
8
+ status_header('200'); // force header('HTTP/1.1 200 OK') for sites without posts
9
+ header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
10
+
11
+ echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?>
12
+ <?xml-stylesheet type="text/xsl" href="'.XMLSF_PLUGIN_URL.'/sitemap.xsl.php?v='.XMLSF_VERSION.'&amp;url='.XMLSF_PLUGIN_URL.'"?>
13
+ <!-- generated-on="'.date('Y-m-d\TH:i:s+00:00').'" -->
14
+ <!-- generator="XML Sitemap Feed plugin for WordPress" -->
15
+ <!-- generator-url="http://4visions.nl/wordpress-plugins/xml-sitemap-feed/" -->
16
+ <!-- generator-version="'.XMLSF_VERSION.'" -->
17
+ ';
18
+
19
+ // presets are changable; please read comments:
20
  $max_priority = 1.0; // Maximum priority value for any URL in the sitemap; set to any other value between 0 and 1.
21
  $min_priority = 0; // Minimum priority value for any URL in the sitemap; set to any other value between 0 and 1.
22
  // NOTE: Changing these values will influence each URL's priority. Priority values are taken by
25
  $frontpage_priority = 1.0; // Your front page priority, usually the same as max priority but if you have any reason
26
  // to change it, please be my guest; set to any other value between 0 and 1.
27
 
28
+ $maxURLS = 50000; // maximum number of URLs allowed in any sitemap.
 
 
 
 
29
  $level_weight = 0.1; // Makes a sub-page loose 10% for each level; set to any other value between 0 and 1.
30
  $month_weight = 0.1; // Fall-back value normally ignored by automatic priority calculation, which
31
  // makes a post loose 10% of priority monthly; set to any other value between 0 and 1.
32
 
33
  // editing below here is not advised!
34
 
35
+ // the main query
36
  query_posts( array(
 
37
  'post_type' => 'any',
38
  'post_status' => 'publish',
39
+ 'caller_get_posts' => '1',
40
+ 'nopaging' => true,
41
+ 'posts_per_page' => -1 )
42
  );
43
 
44
+ global $wp_query;
45
+ $wp_query->is_404 = false; // force is_404() condition to false when on site without posts
46
+ $wp_query->is_feed = true; // force is_feed() condition to true so WP Super Cache includes
47
+ // the sitemap in its feeds cache
48
+
49
  // setup site variables
50
  $_post_count = wp_count_posts('post');
51
  $_page_count = wp_count_posts('page');
52
  $_totalcommentcount = wp_count_comments();
53
 
54
+ $lastmodified_gmt = get_lastmodified('GMT'); // last posts or page modified date
55
+ $lastmodified = mysql2date('U',$lastmodified_gmt); // last posts or page modified date in Unix seconds
56
+ $firstmodified = mysql2date('U',get_firstmodified('GMT')); // uses new get_firstmodified() function defined in xml-sitemap.php !
57
 
58
  // calculated presets
59
  if ($_totalcommentcount->approved > 0)
62
  $comment_weight = 0;
63
 
64
  if ($_post_count->publish > $_page_count->publish) { // site emphasis on posts
65
+ $post_priority = 0.7;
66
+ $page_priority = 0.3;
67
  } else { // site emphasis on pages
68
  $post_priority = 0.4;
69
  $page_priority = 0.8;
70
  }
71
 
72
+ if ( $lastmodified > $firstmodified ) // valid blog age found ?
73
+ $age_weight = ($post_priority - $min_priority) / ($lastmodified - $firstmodified); // calculate relative age weight
74
  else
75
  $age_weight = $month_weight / 2629744 ; // else just do 10% per month (that's a month in seconds)
76
 
77
+ // prepare counter to limit the number of URLs to the absolute max of 50.000
78
+ $counter = 1;
79
+
80
+ // start with the main URL
81
+ ?>
 
 
 
 
82
  <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
83
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
84
  xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
85
  <url>
86
  <loc><?php bloginfo_rss('url') ?>/</loc>
87
+ <lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $lastmodified_gmt, false); ?></lastmod>
88
  <changefreq>daily</changefreq>
89
  <priority>1.0</priority>
90
  </url>
91
  <?php
 
 
 
92
  // and loop away!
93
+ if ( have_posts() ) : while ( have_posts() && $counter < $maxURLS ) : the_post();
94
 
95
  $thispostmodified_gmt = $post->post_modified_gmt; // post GMT timestamp
96
  $thispostmodified = mysql2date('U',$thispostmodified_gmt); // post Unix timestamp
127
  $offset = (($post->comment_count - $average_commentcount) * $comment_weight) - (count($ancestors) * $level_weight);
128
  $priority = $page_priority + $offset;
129
  } else {
130
+ $offset = (($post->comment_count - $average_commentcount) * $comment_weight) - (($lastmodified - $thispostmodified) * $age_weight);
131
  $priority = $post_priority + $offset;
132
  }
133
  // trim priority
151
  <?php
152
  $counter++;
153
 
154
+ endwhile; endif;
155
+ ?>
156
  </urlset>
readme.txt CHANGED
@@ -1,24 +1,26 @@
1
  === XML Sitemap Feed ===
2
  Contributors: RavanH
3
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap&item_number=3%2e0&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8
4
  Tags: sitemap, xml sitemap, sitemap.xml, google, yahoo, bing, wpmu, feed
5
  Requires at least: 2.6
6
  Tested up to: 3.0
7
- Stable tag: 3.7
8
 
9
  Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others.
10
 
11
  == Description ==
12
 
13
- This plugin dynamically creates an XML feed that complies with the XML Sitemap protocol. There are no options to be set and the feed becomes instantly available after activation on yourblogurl.tld/feed/sitemap/ and for backward compatibility on yourblogurl.tld/sitemap.xml or yourblogurl.tld/index.php?feed=sitemap if you do not use a fancy permalink structure, ready for indexing by search engines like Google, Yahoo, MSN, Ask.com and others.
14
 
15
- A reference to it is added to your (by WordPress dynamically created) robots.txt on yourblogurl.tld/robots.txt to tell search engines where to find your XML Sitemap. If you do not use fancy URL's in WordPress, if you have WP installed in a subdirectory or if you use WP for pages only and do not have any posts, WordPress does not generate a robots.txt output. You'll have to create your own and upload it to your site root. See FAQ's.
 
 
16
 
17
  = Advantages =
18
 
19
  * The main advantage of this plugin over other XML Sitemap plugins is **simplicity**. No need to change file or folder permissions, move files or spend time on a difficult plugin options page. In fact, there are no options at all!
20
  * Completely **automatic** post URL _priority_ and _change frequency_ calculation based on post age and comment/trackback activity.
21
- * Works out-of-the-box, even on **multi-site / shared codebase / multi-blog setups** like [WordPress MU](http://mu.wordpress.org/), WP 3.0 in MultiSite mode and others.
22
  * Also works when **Network Activated** or placed in **/mu-plugins/** on WP 3.0 in MS mode and WPMU and even takes care to exclude any tags blogs to avoid malus points for link spamming.
23
 
24
  = Limitations =
@@ -26,7 +28,7 @@ A reference to it is added to your (by WordPress dynamically created) robots.txt
26
  * The feed contains the front page and all posts and pages but _excludes_ category, tag and other dynamic archive pages. This should not be a problem and by most it is even advised. There even are SEO plugins around that actively make these archive pages non-index-able by search engines.
27
  * Except by _re-saving_ older posts from time to time (keeping the lastmod date fairly recent to ensure automatic high priority calculation for those urls) there is no way to manually set the priority of individual posts/pages in the sitemap. See the Faq's for more.
28
  * This plugin does not ping any search engines. But then, WordPress does this by default already via the Ping-o-Matic service so why bother? See the Faq's for more.
29
- * Since the feed is dynamically created, on _very_ large sites the creation process might take a while. Search engines are said to have a short fuse about waiting for a sitemap, so if your site is huge you may want to consider using a cache plugin that also (pre)caches feeds. If you are unfamiliar with caching and server setup start with a simple plugin such as Quick Cache but if you are looking for more options you might find solace in WP Super Cache of W3 Total Cache.
30
 
31
  = Translations =
32
 
@@ -54,7 +56,7 @@ follow these simple steps:
54
 
55
  4. If you have been using another XML Sitemap plugin before, check your site root and remove any created sitemap.xml file that remained there.
56
 
57
- Done! Check your sparkling new XML Sitemap by visiting yourblogurl.tld/feed/sitemap/ (adapted to your domain name ofcourse) with a browser or any online XML Sitemap validator. You might also want to check if the sitemap is listed in your yourblogurl.tld/robots.txt file.
58
 
59
  = WordPress 3+ in Multi Site mode =
60
 
@@ -84,15 +86,14 @@ Yes and No. This plugin has no options page so there is no way to manually set t
84
 
85
  This feature can be used to your advantage: by re-saving your most important older posts from time to time, keeping the **lastmod date** fairly recent, you can ensure a priority of at least 80% (0.8) for those URLs. And if you have comments on on those pages, the priority will even go up to 90% (0.9).
86
 
87
- If you cannot live with these rules, edit the values `$min_priority`, `$max_priority` and `$frontpage_priority` in xml-sitemap-feed/feed-sitemap.php
88
 
89
  = Do I need to submit the sitemap to search engines? =
90
 
91
- No. In normal circumstances, your site will be indexed by the major search engines before you know it. The search engines will be looking for a robots.txt file and (with this plugin activated) find a pointer in it to the XML Sitemap on your blog. The search engines will return on a regular basis to see if your site has updates.
92
-
93
- Read more about _Ping-O-Matic_ under **Does this plugin ping search engines** (below) to make sure your site is under _normal circumstances_ ;)
94
 
95
- But if you have a server without rewrite rules, use your blog without fancy URLs or have it installed in a subdirectory, read **Do I need to change my robots.txt** for more instructions.
96
 
97
  = Does this plugin ping search engines? =
98
 
@@ -112,7 +113,7 @@ You can always take a [Google Webmaster Tools account](https://www.google.com/we
112
 
113
  That depends. In normal circumstances, if you have no physical robots.txt file in your site root, the new sitemap url will be automatically added to the dynamic robots.txt that is generated by WordPress. But in some cases this might not be the case.
114
 
115
- If you use a static robots.txt file in your website root, you will need to open it in a text editor. If there is already a line with `Sitemap: http://yourblogurl.tld/sitemap.xml` you can just leave it like it is. But if there is no sitemap referrence there, add a line like `Sitemap: http://yourblogurl.tld/feed/sitemap/` (adapt to your site url) to make search engines find your XML Sitemap.
116
 
117
  Or if you have WP installed in a subdirectory, on a server without rewrite_rules or if you do not use fancy URLs in your Permalink structure settings. In these cases, WordPress will need a little help in getting ready for XML Sitemap indexing. Read on in the **WordPress** section for more.
118
 
@@ -120,18 +121,18 @@ Or if you have WP installed in a subdirectory, on a server without rewrite_rules
120
 
121
  That depends on where the index.php and .htaccess of your installation resides. If it is in the root, meaning WP is installed in a subdir but the blog is accessible from your domain root, you do not have to do anything. It should work out of the box. However, if the index.php is (e.g. still with your wp-config.php and all other WP files) in a subdir, meaning your blog is only accessible via that subdir, you need to manage your own robots.txt file in your domain root. It _has_ to be in the root (!) and needs a line starting with `Sitemap:` followed by the full URL to the sitemap feed provided by XML Sitemap Feed plugin. Like:
122
  `
123
- Sitemap: http://yourblogurl.tld/subdir/feed/sitemap/
124
  `
125
 
126
  If you already have a robots.txt file with another Sitemap referrence like it, you might want to read more about creating an XML Sitemap Index on [sitemaps.org](http://www.sitemaps.org/protocol.php#index) to be able to referrence both sitemaps.
127
 
128
  = Do I need to use a fancy Permalink structure? =
129
 
130
- No. While I would advise you to use any one of the nicer Permalink structures, you might not be able to (or don't want to) do that. If so, you can still use this plugin:
131
 
132
- Check to see if the URL yourblogurl.tld/index.php?feed=sitemap does produce a feed. Now manually upload your own robots.txt file to your website root containing:
133
  `
134
- Sitemap: http://yourblogurl.tld/index.php?feed=sitemap
135
 
136
  User-agent: *
137
  Allow: /
@@ -140,7 +141,7 @@ You can also choose to notify major search engines of your new XML sitemap manua
140
 
141
  = Can I change the sitemap name/URL? =
142
 
143
- No. If you have fancy URL's turned ON in WordPress (Permalinks), the sitemap url that you manually submit to Google (if you are impatient) should be `yourblogurl.tld/feed/sitemap/` but if you have the Permalinks' Default option set the feed is only available via `yourblogurl.tld/?feed=sitemap`.
144
 
145
  = Where can I customize the xml output? =
146
 
@@ -156,7 +157,11 @@ The sitemap is dynamically generated just like a feed. There is no actual file c
156
 
157
  You are most likely looking at a sitemap.xml file that has been created by you or another XML Sitemap plugin before you started using this plugin. Just remove it and let the plugin dynamically generate it just like a feed. There is no actual file created.
158
 
159
- = I get a 404 page instead of both sitemap.xml and robots.txt! =
 
 
 
 
160
 
161
  There are plugins like Event Calendar (at least v.3.2.beta2) known to mess with rewrite rules, causing problems with WordPress internal feeds and robots.txt generation and thus conflict with the XML Sitemap Feed plugin. Deactivate all plugins and see if you get a basic robots.txt file showing:
162
  `
@@ -171,7 +176,7 @@ There is a know issue with WordPress (at least up to 2.8) not generating a robot
171
 
172
  To get around this, you might either at least write one post and give it _Private_ status or alternatively create your own robots.txt file containing:
173
  `
174
- Sitemap: http://yourblogurl.tld/feed/sitemap/
175
 
176
  User-agent: *
177
  Allow: /
@@ -186,8 +191,20 @@ Yes.
186
 
187
  Yes.
188
 
 
 
 
 
 
189
  == Changelog ==
190
 
 
 
 
 
 
 
 
191
  = 3.7 =
192
  * massive changefreq calculation improvement
193
  * further priority calulation improvement taking last comment date into account
@@ -232,3 +249,10 @@ Yes.
232
  * rework from Patrick Chia's [Standard XML Sitemaps](http://wordpress.org/extend/plugins/standard-xml-sitemap/)
233
  * increased post urls limit from 100 to 1000 (of max. 50,000 allowed by the Sitemap protocol)
234
 
 
 
 
 
 
 
 
1
  === XML Sitemap Feed ===
2
  Contributors: RavanH
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=3%2e8&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8
4
  Tags: sitemap, xml sitemap, sitemap.xml, google, yahoo, bing, wpmu, feed
5
  Requires at least: 2.6
6
  Tested up to: 3.0
7
+ Stable tag: 3.7.4
8
 
9
  Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others.
10
 
11
  == Description ==
12
 
13
+ This plugin dynamically creates an feed that complies with the **XML Sitemap** protocol. There are no options to be set and the feed becomes instantly available after activation on yourblogurl.tld/sitemap.xml and on yourblogurl.tld/?feed=sitemap for if you do not use a fancy permalink structure, ready for indexing by search engines like Google, Yahoo, MSN, Ask.com and others.
14
 
15
+ A reference to it is added to your (by WordPress dynamically created) **robots.txt** on yourblogurl.tld/robots.txt to tell search engines where to find your XML Sitemap.
16
+
17
+ *NOTE:* If you _do not use fancy URL's_, if you have WordPress installed in a _subdirectory_ or if have _only pages_ and no posts, WordPress does **not** generate a robots.txt output. _You'll have to create your own and upload it to your site root!_ See FAQ's.
18
 
19
  = Advantages =
20
 
21
  * The main advantage of this plugin over other XML Sitemap plugins is **simplicity**. No need to change file or folder permissions, move files or spend time on a difficult plugin options page. In fact, there are no options at all!
22
  * Completely **automatic** post URL _priority_ and _change frequency_ calculation based on post age and comment/trackback activity.
23
+ * Works out-of-the-box, even on **multi-site / shared codebase / multi-blog setups** like WordPress MU, WP 3.0 in MultiSite (WPMS) mode and others.
24
  * Also works when **Network Activated** or placed in **/mu-plugins/** on WP 3.0 in MS mode and WPMU and even takes care to exclude any tags blogs to avoid malus points for link spamming.
25
 
26
  = Limitations =
28
  * The feed contains the front page and all posts and pages but _excludes_ category, tag and other dynamic archive pages. This should not be a problem and by most it is even advised. There even are SEO plugins around that actively make these archive pages non-index-able by search engines.
29
  * Except by _re-saving_ older posts from time to time (keeping the lastmod date fairly recent to ensure automatic high priority calculation for those urls) there is no way to manually set the priority of individual posts/pages in the sitemap. See the Faq's for more.
30
  * This plugin does not ping any search engines. But then, WordPress does this by default already via the Ping-o-Matic service so why bother? See the Faq's for more.
31
+ * Since the feed is dynamically created, on _very_ large sites the creation process might take a while. Search engines are said to have a short fuse about waiting for a sitemap, so if your site is huge you may want to consider using a cache plugin that also (pre)caches feeds. If you are unfamiliar with caching and server setup start with a simple plugin such as Quick Cache but if you are looking for more options you might find solace in WP Super Cache or W3 Total Cache.
32
 
33
  = Translations =
34
 
56
 
57
  4. If you have been using another XML Sitemap plugin before, check your site root and remove any created sitemap.xml file that remained there.
58
 
59
+ Done! Check your sparkling new XML Sitemap by visiting yourblogurl.tld/sitemap.xml (adapted to your domain name ofcourse) with a browser or any online XML Sitemap validator. You might also want to check if the sitemap is listed in your yourblogurl.tld/robots.txt file.
60
 
61
  = WordPress 3+ in Multi Site mode =
62
 
86
 
87
  This feature can be used to your advantage: by re-saving your most important older posts from time to time, keeping the **lastmod date** fairly recent, you can ensure a priority of at least 80% (0.8) for those URLs. And if you have comments on on those pages, the priority will even go up to 90% (0.9).
88
 
89
+ If you cannot live with these rules, edit the values `$min_priority`, `$max_priority` and `$frontpage_priority` in xml-sitemap-feed/feed-sitemap.php but be careful to not do an automatic upgrade or it will overwrite your customisation.
90
 
91
  = Do I need to submit the sitemap to search engines? =
92
 
93
+ No. In normal circumstances, your site will be indexed by the major search engines before you know it. The search engines will be looking for a robots.txt file and (with this plugin activated) find a pointer in it to the XML Sitemap on your blog. The search engines will return on a regular basis to see if your site has updates.
94
+ ( Read more about _Ping-O-Matic_ under **Does this plugin ping search engines** (below) to make sure your site is under _normal circumstances_ ;) )
 
95
 
96
+ **But** if you have a server _without rewrite rules_, use your blog _without fancy URLs_ (meaning, you have WordPress Permalinks set to the old Default value) or have it installed in a _subdirectory_, read **Do I need to change my robots.txt** for more instructions.
97
 
98
  = Does this plugin ping search engines? =
99
 
113
 
114
  That depends. In normal circumstances, if you have no physical robots.txt file in your site root, the new sitemap url will be automatically added to the dynamic robots.txt that is generated by WordPress. But in some cases this might not be the case.
115
 
116
+ If you use a static robots.txt file in your website root, you will need to open it in a text editor. If there is already a line with `Sitemap: http://yourblogurl.tld/sitemap.xml` you can just leave it like it is. But if there is no sitemap referrence there, add it (adapted to your site url) to make search engines find your XML Sitemap.
117
 
118
  Or if you have WP installed in a subdirectory, on a server without rewrite_rules or if you do not use fancy URLs in your Permalink structure settings. In these cases, WordPress will need a little help in getting ready for XML Sitemap indexing. Read on in the **WordPress** section for more.
119
 
121
 
122
  That depends on where the index.php and .htaccess of your installation resides. If it is in the root, meaning WP is installed in a subdir but the blog is accessible from your domain root, you do not have to do anything. It should work out of the box. However, if the index.php is (e.g. still with your wp-config.php and all other WP files) in a subdir, meaning your blog is only accessible via that subdir, you need to manage your own robots.txt file in your domain root. It _has_ to be in the root (!) and needs a line starting with `Sitemap:` followed by the full URL to the sitemap feed provided by XML Sitemap Feed plugin. Like:
123
  `
124
+ Sitemap: http://yourblogurl.tld/subdir/sitemap.xml
125
  `
126
 
127
  If you already have a robots.txt file with another Sitemap referrence like it, you might want to read more about creating an XML Sitemap Index on [sitemaps.org](http://www.sitemaps.org/protocol.php#index) to be able to referrence both sitemaps.
128
 
129
  = Do I need to use a fancy Permalink structure? =
130
 
131
+ No. While I would advise you to use any one of the nicer Permalink structures for better indexing, you might not be able to (or don't want to) do that. If so, you can still use this plugin:
132
 
133
+ Check to see if the URL yourblogurl.tld/?feed=sitemap does produce a feed. Now manually upload your own robots.txt file to your website root containing:
134
  `
135
+ Sitemap: http://yourblogurl.tld/?feed=sitemap
136
 
137
  User-agent: *
138
  Allow: /
141
 
142
  = Can I change the sitemap name/URL? =
143
 
144
+ No. If you have fancy URL's turned ON in WordPress (Permalinks), the sitemap url that you manually submit to Google (if you are impatient) should be `yourblogurl.tld/sitemap.xml` but if you have the Permalinks' Default option set the feed is only available via `yourblogurl.tld/?feed=sitemap`.
145
 
146
  = Where can I customize the xml output? =
147
 
157
 
158
  You are most likely looking at a sitemap.xml file that has been created by you or another XML Sitemap plugin before you started using this plugin. Just remove it and let the plugin dynamically generate it just like a feed. There is no actual file created.
159
 
160
+ = I get a 404 page instead of my sitemap.xml! =
161
+
162
+ Try to refresh the Permalink structure in WordPress. Go to Settings > Permalinks and re-save them. Then reload the XML Sitemap in your browser with a clean browser cache. ( Try Ctrl+R to bypass the browser cache -- this works on most but not all browsers. )
163
+
164
+ = I still get a 404 page instead of both sitemap.xml and robots.txt! =
165
 
166
  There are plugins like Event Calendar (at least v.3.2.beta2) known to mess with rewrite rules, causing problems with WordPress internal feeds and robots.txt generation and thus conflict with the XML Sitemap Feed plugin. Deactivate all plugins and see if you get a basic robots.txt file showing:
167
  `
176
 
177
  To get around this, you might either at least write one post and give it _Private_ status or alternatively create your own robots.txt file containing:
178
  `
179
+ Sitemap: http://yourblogurl.tld/sitemap.xml
180
 
181
  User-agent: *
182
  Allow: /
191
 
192
  Yes.
193
 
194
+ == Screenshots ==
195
+
196
+ 1. XML Sitemap feed viewed in a normal browser. For human eyes only ;)
197
+ 2. XML Sitemap source as read by search engines.
198
+
199
  == Changelog ==
200
 
201
+ = 3.7.4 =
202
+ * switch from `add_feed` (on init) to the `do_feed_$feed` hook
203
+ * BUGFIX: `is_404()` condition TRUE and Response Header 404 on sites without posts
204
+ * BUGFIX: `is_feed()` condition FALSE after custom query_posts
205
+ * BUGFIX: no lastmod on home url when only pages on a site
206
+ * BUGFIX: stylesheet url wrong when WP installed in a subdir
207
+
208
  = 3.7 =
209
  * massive changefreq calculation improvement
210
  * further priority calulation improvement taking last comment date into account
249
  * rework from Patrick Chia's [Standard XML Sitemaps](http://wordpress.org/extend/plugins/standard-xml-sitemap/)
250
  * increased post urls limit from 100 to 1000 (of max. 50,000 allowed by the Sitemap protocol)
251
 
252
+ == Upgrade Notice ==
253
+
254
+ = 3.7.4 =
255
+ Hook improvement and bugfix release.
256
+
257
+ = 3.7 =
258
+ Massive changefreq calculation improvement and further priority calculation improvement taking last comment date into account.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
sitemap.xsl.php CHANGED
@@ -69,7 +69,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>
69
  </table>
70
  </div>
71
  <div id="footer">
72
- <strong>XML Sitemap</strong> generated by <a href="http://4visions.nl/en/index.php?section=57" title="XML Sitemap Feed plugin for WordPress">XML Sitemap Feed <?php echo $_GET['v'] ?></a> running on <a href="http://wordpress.org/">WordPress</a>.
73
  </div>
74
  </body>
75
  </html>
69
  </table>
70
  </div>
71
  <div id="footer">
72
+ <img src="<?php echo $_GET['url'] ?>/sitemapxml.gif" alt="XML Sitemap" title="XML Sitemap" /> generated by <a href="http://4visions.nl/en/index.php?section=57" title="XML Sitemap Feed plugin for WordPress">XML Sitemap Feed <?php echo $_GET['v'] ?></a> running on <a href="http://wordpress.org/">WordPress</a>.
73
  </div>
74
  </body>
75
  </html>
sitemapxml.gif ADDED
Binary file
xml-sitemap.php CHANGED
@@ -1,12 +1,12 @@
1
  <?php
2
  /*
3
  Plugin Name: XML Sitemap Feed
4
- Plugin URI: http://4visions.nl/portfolio/wordpress-plugins/xml-sitemap-feed/
5
- Description: Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others.
6
- Version: 3.7
7
  Author: RavanH
8
  Author URI: http://4visions.nl/
9
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=2%2e6%2e2%2e9&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8
10
  */
11
 
12
  /* Copyright 2009 RavanH (http://4visions.nl/ email : ravanhagen@gmail.com)
@@ -37,44 +37,37 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravan
37
  -------------------- */
38
 
39
  // set version
40
- define('XMLSF_VERSION','3.7');
41
 
42
  // dir
43
  $xmlsf_dir = dirname(__FILE__);
44
 
45
  // check if xml-sitemap.php is moved one dir up like in WPMU's /mu-plugins/
46
- if (file_exists($xmlsf_dir.'/xml-sitemap-feed'))
 
47
  define('XMLSF_PLUGIN_DIR', $xmlsf_dir.'/xml-sitemap-feed');
48
- else
 
49
  define('XMLSF_PLUGIN_DIR', $xmlsf_dir);
50
-
51
- // url
52
- define('XMLSF_PLUGIN_URL', WP_PLUGIN_URL.'/'.basename($xmlsf_dir));
53
 
54
  /* --------------------
55
  FUNCTIONS
56
  -------------------- */
57
 
58
  // FEEDS //
59
- // set the XML feed up
60
- function xml_sitemap_add_feed() {
61
- add_feed('sitemap','do_feed_sitemap');
62
- }
63
-
64
- // TEMPLATES //
65
- // set the XML feed template up
66
- if ( !function_exists(do_feed_sitemap) ) {
67
- function do_feed_sitemap() {
68
  load_template( XMLSF_PLUGIN_DIR . '/feed-sitemap.php' );
69
  }
70
- }
71
 
72
  // REWRITES //
73
- // add the rewrite rules
74
  function xml_sitemap_rewrite($wp_rewrite) {
75
  $feed_rules = array(
76
- 'sitemap\.xml$' => $wp_rewrite->index . '?feed=sitemap',
77
- 'feed/sitemap$' => $wp_rewrite->index . '?feed=sitemap'
78
  );
79
  $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
80
  }
@@ -87,7 +80,8 @@ function xml_sitemap_flush_rewrite_rules() {
87
  // ROBOTSTXT //
88
  // add sitemap location in robots.txt generated by WP
89
  function xml_sitemap_robots() {
90
- echo "\nSitemap: ".get_feed_link('sitemap')."\n\n";
 
91
  }
92
 
93
  // DE/ACTIVATION
@@ -102,7 +96,123 @@ function xml_sitemap_deactivate() {
102
  xml_sitemap_flush_rewrite_rules();
103
  }
104
 
 
105
  // MISSING WORDPRESS FUNCTIONS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  /**
107
  * Retrieve first post modified date depending on timezone.
108
  *
@@ -118,8 +228,8 @@ function xml_sitemap_deactivate() {
118
  * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
119
  * @return string The date of the oldest modified post.
120
  */
121
- if( !function_exists(get_firstpostmodified) ) {
122
- function get_firstpostmodified($timezone = 'server') {
123
  global $wpdb;
124
 
125
  $add_seconds_server = date('Z');
@@ -149,7 +259,56 @@ function get_firstpostmodified($timezone = 'server') {
149
  wp_cache_set( "firstpostmodified:$timezone", $firstpostmodified, 'timeinfo' );
150
 
151
  return apply_filters( 'get_firstpostmodified', $firstpostmodified, $timezone );
 
152
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  }
154
 
155
  /**
@@ -159,7 +318,7 @@ function get_firstpostmodified($timezone = 'server') {
159
  * server time. The 'blog' value is the date when the last post was posted. The
160
  * 'gmt' is when the last post was posted in GMT formatted date.
161
  *
162
- * Reverse of get_lastpostmodified defined in wp-includes/post.php since 0.71
163
  *
164
  * @uses $wpdb
165
  * @uses $cache_firstpostdate
@@ -169,8 +328,8 @@ function get_firstpostmodified($timezone = 'server') {
169
  * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
170
  * @return string The date of the last post.
171
  */
172
- if( !function_exists(get_firstpostdate) ) {
173
- function get_firstpostdate($timezone = 'server') {
174
  global $cache_firstpostdate, $wpdb, $blog_id;
175
  $add_seconds_server = date('Z');
176
  if ( !isset($cache_firstpostdate[$blog_id][$timezone]) ) {
@@ -190,8 +349,50 @@ function get_firstpostdate($timezone = 'server') {
190
  $firstpostdate = $cache_firstpostdate[$blog_id][$timezone];
191
  }
192
  return apply_filters( 'get_firstpostdate', $firstpostdate, $timezone );
 
193
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  }
 
195
  /* --------------------
196
  HOOKS
197
  -------------------- */
@@ -210,7 +411,7 @@ if ( $wpdb->blogid && function_exists('get_site_option') && get_site_option('tag
210
  return;
211
  } else {
212
  // FEEDS
213
- add_action('init', 'xml_sitemap_add_feed');
214
 
215
  // REWRITES
216
  add_filter('generate_rewrite_rules', 'xml_sitemap_rewrite');
@@ -223,4 +424,3 @@ if ( $wpdb->blogid && function_exists('get_site_option') && get_site_option('tag
223
  register_activation_hook( __FILE__, 'xml_sitemap_activate' );
224
  register_deactivation_hook( __FILE__, 'xml_sitemap_deactivate' );
225
 
226
- ?>
1
  <?php
2
  /*
3
  Plugin Name: XML Sitemap Feed
4
+ Plugin URI: http://4visions.nl/wordpress-plugins/xml-sitemap-feed/
5
+ Description: Creates a feed that complies with the XML Sitemap protocol ready for indexing by Google, Yahoo, Bing, Ask and others. Happy with it? Please leave me a <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=3%2e8&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8">Tip</a></strong> for development and support time. Thanks :)
6
+ Version: 3.7.4
7
  Author: RavanH
8
  Author URI: http://4visions.nl/
9
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=3%2e8&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8
10
  */
11
 
12
  /* Copyright 2009 RavanH (http://4visions.nl/ email : ravanhagen@gmail.com)
37
  -------------------- */
38
 
39
  // set version
40
+ define('XMLSF_VERSION','3.7.4');
41
 
42
  // dir
43
  $xmlsf_dir = dirname(__FILE__);
44
 
45
  // check if xml-sitemap.php is moved one dir up like in WPMU's /mu-plugins/
46
+ // NOTE: don't use WP_PLUGIN_URL to avoid problems when installed in /mu-plugins/
47
+ if (file_exists($xmlsf_dir.'/xml-sitemap-feed')) {
48
  define('XMLSF_PLUGIN_DIR', $xmlsf_dir.'/xml-sitemap-feed');
49
+ define('XMLSF_PLUGIN_URL', plugins_url('xml-sitemap-feed', __FILE__) );
50
+ } else {
51
  define('XMLSF_PLUGIN_DIR', $xmlsf_dir);
52
+ define('XMLSF_PLUGIN_URL', plugins_url('', __FILE__) );
53
+ }
 
54
 
55
  /* --------------------
56
  FUNCTIONS
57
  -------------------- */
58
 
59
  // FEEDS //
60
+ // set up the feed template
61
+ function xml_sitemap_load_template() {
 
 
 
 
 
 
 
62
  load_template( XMLSF_PLUGIN_DIR . '/feed-sitemap.php' );
63
  }
 
64
 
65
  // REWRITES //
66
+ // add sitemap rewrite rules
67
  function xml_sitemap_rewrite($wp_rewrite) {
68
  $feed_rules = array(
69
+ 'sitemap.xml' => $wp_rewrite->index . '?feed=sitemap',
70
+ 'feed/sitemap' => $wp_rewrite->index . '?feed=sitemap'
71
  );
72
  $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
73
  }
80
  // ROBOTSTXT //
81
  // add sitemap location in robots.txt generated by WP
82
  function xml_sitemap_robots() {
83
+ if ( '0' != get_option( 'blog_public' ) )
84
+ echo "\nSitemap: ".get_option('home')."/sitemap.xml\n\n";
85
  }
86
 
87
  // DE/ACTIVATION
96
  xml_sitemap_flush_rewrite_rules();
97
  }
98
 
99
+
100
  // MISSING WORDPRESS FUNCTIONS
101
+
102
+ if( !function_exists('get_firstmodified') ) {
103
+ function get_firstmodified($timezone = 'server') {
104
+ $firstpostmodified = get_firstpostmodified($timezone);
105
+ $firstpagemodified = get_firstpagemodified($timezone);
106
+ if ( mysql2date('U',$firstpostmodified) < mysql2date('U',$firstpagemodified) )
107
+ return $firstpostmodified;
108
+ else
109
+ return $firstpagemodified;
110
+ }
111
+ }
112
+ if( !function_exists('get_lastmodified') ) {
113
+ function get_lastmodified($timezone = 'server') {
114
+ $lastpostmodified = get_lastpostmodified($timezone);
115
+ $lastpagemodified = get_lastpagemodified($timezone);
116
+ if ( mysql2date('U',$lastpostmodified) > mysql2date('U',$lastpagemodified) )
117
+ return $lastpostmodified;
118
+ else
119
+ return $lastpagemodified;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Retrieve last page modified date depending on timezone.
125
+ *
126
+ * The server timezone is the default and is the difference between GMT and
127
+ * server time. The 'blog' value is just when the last post was modified. The
128
+ * 'gmt' is when the last post was modified in GMT time.
129
+ *
130
+ * Adaptation of get_lastpostmodified defined in wp-includes/post.php since 1.2.0
131
+ *
132
+ * @uses $wpdb
133
+ * @uses $blog_id
134
+ * @uses apply_filters() Calls 'get_lastpagemodified' filter
135
+ *
136
+ * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
137
+ * @return string The date the post was last modified.
138
+ */
139
+ if( !function_exists('get_lastpagemodified') ) {
140
+ function get_lastpagemodified($timezone = 'server') {
141
+ global $wpdb;
142
+
143
+ $add_seconds_server = date('Z');
144
+ $timezone = strtolower( $timezone );
145
+
146
+ $lastpagemodified = wp_cache_get( "lastpagemodified:$timezone", 'timeinfo' );
147
+ if ( $lastpagemodified )
148
+ return apply_filters( 'get_lastpagemodified', $lastpagemodified, $timezone );
149
+
150
+ switch ( strtolower($timezone) ) {
151
+ case 'gmt':
152
+ $lastpagemodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_modified_gmt DESC LIMIT 1");
153
+ break;
154
+ case 'blog':
155
+ $lastpagemodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_modified_gmt DESC LIMIT 1");
156
+ break;
157
+ case 'server':
158
+ $lastpagemodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_modified_gmt DESC LIMIT 1");
159
+ break;
160
+ }
161
+
162
+ $lastpagedate = get_lastpagedate($timezone);
163
+ if ( $lastpagedate > $lastpagemodified )
164
+ $lastpagemodified = $lastpagedate;
165
+
166
+ if ( $lastpagemodified )
167
+ wp_cache_set( "lastpagemodified:$timezone", $lastpagemodified, 'timeinfo' );
168
+
169
+ return apply_filters( 'get_lastpagemodified', $lastpagemodified, $timezone );
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Retrieve the date that the last page was published.
175
+ *
176
+ * The server timezone is the default and is the difference between GMT and
177
+ * server time. The 'blog' value is the date when the last post was posted. The
178
+ * 'gmt' is when the last post was posted in GMT formatted date.
179
+ *
180
+ * Adaptation of get_lastpostdate defined in wp-includes/post.php since 0.71
181
+ *
182
+ * @uses $wpdb
183
+ * @uses $blog_id
184
+ * @uses apply_filters() Calls 'get_lastpagedate' filter
185
+ *
186
+ * @global mixed $cache_lastpagedate Stores the last post date
187
+ * @global mixed $pagenow The current page being viewed
188
+ *
189
+ * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
190
+ * @return string The date of the last post.
191
+ */
192
+ if( !function_exists('get_lastpagedate') ) {
193
+ function get_lastpagedate($timezone = 'server') {
194
+ global $cache_lastpagedate, $wpdb, $blog_id;
195
+ $add_seconds_server = date('Z');
196
+ if ( !isset($cache_lastpagedate[$blog_id][$timezone]) ) {
197
+ switch(strtolower($timezone)) {
198
+ case 'gmt':
199
+ $lastpagedate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_date_gmt DESC LIMIT 1");
200
+ break;
201
+ case 'blog':
202
+ $lastpagedate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_date_gmt DESC LIMIT 1");
203
+ break;
204
+ case 'server':
205
+ $lastpagedate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_date_gmt DESC LIMIT 1");
206
+ break;
207
+ }
208
+ $cache_lastpagedate[$blog_id][$timezone] = $lastpagedate;
209
+ } else {
210
+ $lastpagedate = $cache_lastpagedate[$blog_id][$timezone];
211
+ }
212
+ return apply_filters( 'get_lastpagedate', $lastpagedate, $timezone );
213
+ }
214
+ }
215
+
216
  /**
217
  * Retrieve first post modified date depending on timezone.
218
  *
228
  * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
229
  * @return string The date of the oldest modified post.
230
  */
231
+ if( !function_exists('get_firstpostmodified') ) {
232
+ function get_firstpostmodified($timezone = 'server') {
233
  global $wpdb;
234
 
235
  $add_seconds_server = date('Z');
259
  wp_cache_set( "firstpostmodified:$timezone", $firstpostmodified, 'timeinfo' );
260
 
261
  return apply_filters( 'get_firstpostmodified', $firstpostmodified, $timezone );
262
+ }
263
  }
264
+
265
+ /**
266
+ * Retrieve first page modified date depending on timezone.
267
+ *
268
+ * The server timezone is the default and is the difference between GMT and
269
+ * server time. The 'blog' value is the date when the last post was posted. The
270
+ * 'gmt' is when the last post was posted in GMT formatted date.
271
+ *
272
+ * Adaptation of get_firstpostmodified defined in this file
273
+ *
274
+ * @uses $wpdb
275
+ * @uses apply_filters() Calls 'get_firstpagemodified' filter
276
+ *
277
+ * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
278
+ * @return string The date of the oldest modified page.
279
+ */
280
+ if( !function_exists('get_firstpagemodified') ) {
281
+ function get_firstpagemodified($timezone = 'server') {
282
+ global $wpdb;
283
+
284
+ $add_seconds_server = date('Z');
285
+ $timezone = strtolower( $timezone );
286
+
287
+ $firstpagemodified = wp_cache_get( "firstpagemodified:$timezone", 'timeinfo' );
288
+ if ( $firstpagemodified )
289
+ return apply_filters( 'get_firstpagemodified', $firstpagemodified, $timezone );
290
+
291
+ switch ( strtolower($timezone) ) {
292
+ case 'gmt':
293
+ $firstpagemodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_modified_gmt ASC LIMIT 1");
294
+ break;
295
+ case 'blog':
296
+ $firstpagemodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_modified_gmt ASC LIMIT 1");
297
+ break;
298
+ case 'server':
299
+ $firstpagemodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_modified_gmt ASC LIMIT 1");
300
+ break;
301
+ }
302
+
303
+ $firstpagedate = get_firstpagedate($timezone);
304
+ if ( $firstpagedate > $firstpagemodified )
305
+ $firstpagemodified = $firstpagedate;
306
+
307
+ if ( $firstpagemodified )
308
+ wp_cache_set( "firstpagemodified:$timezone", $firstpagemodified, 'timeinfo' );
309
+
310
+ return apply_filters( 'get_firstpagemodified', $firstpagemodified, $timezone );
311
+ }
312
  }
313
 
314
  /**
318
  * server time. The 'blog' value is the date when the last post was posted. The
319
  * 'gmt' is when the last post was posted in GMT formatted date.
320
  *
321
+ * Reverse of get_lastpostdate defined in wp-includes/post.php since 0.71
322
  *
323
  * @uses $wpdb
324
  * @uses $cache_firstpostdate
328
  * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
329
  * @return string The date of the last post.
330
  */
331
+ if( !function_exists('get_firstpostdate') ) {
332
+ function get_firstpostdate($timezone = 'server') {
333
  global $cache_firstpostdate, $wpdb, $blog_id;
334
  $add_seconds_server = date('Z');
335
  if ( !isset($cache_firstpostdate[$blog_id][$timezone]) ) {
349
  $firstpostdate = $cache_firstpostdate[$blog_id][$timezone];
350
  }
351
  return apply_filters( 'get_firstpostdate', $firstpostdate, $timezone );
352
+ }
353
  }
354
+
355
+ /**
356
+ * Retrieve the date that the first post was published.
357
+ *
358
+ * The server timezone is the default and is the difference between GMT and
359
+ * server time. The 'blog' value is the date when the last post was posted. The
360
+ * 'gmt' is when the last post was posted in GMT formatted date.
361
+ *
362
+ * Adaptation of get_firstpostdate defined in this file
363
+ *
364
+ * @uses $wpdb
365
+ * @uses $cache_firstpagedate
366
+ * @uses $blog_id
367
+ * @uses apply_filters() Calls 'get_firstpagedate' filter
368
+ *
369
+ * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
370
+ * @return string The date of the last post.
371
+ */
372
+ if( !function_exists('get_firstpagedate') ) {
373
+ function get_firstpagedate($timezone = 'server') {
374
+ global $cache_firstpagedate, $wpdb, $blog_id;
375
+ $add_seconds_server = date('Z');
376
+ if ( !isset($cache_firstpagedate[$blog_id][$timezone]) ) {
377
+ switch(strtolower($timezone)) {
378
+ case 'gmt':
379
+ $firstpagedate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_date_gmt ASC LIMIT 1");
380
+ break;
381
+ case 'blog':
382
+ $firstpagedate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_date_gmt ASC LIMIT 1");
383
+ break;
384
+ case 'server':
385
+ $firstpagedate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' ORDER BY post_date_gmt ASC LIMIT 1");
386
+ break;
387
+ }
388
+ $cache_firstpagedate[$blog_id][$timezone] = $firstpagedate;
389
+ } else {
390
+ $firstpagedate = $cache_firstpagedate[$blog_id][$timezone];
391
+ }
392
+ return apply_filters( 'get_firstpagedate', $firstpagedate, $timezone );
393
+ }
394
  }
395
+
396
  /* --------------------
397
  HOOKS
398
  -------------------- */
411
  return;
412
  } else {
413
  // FEEDS
414
+ add_action('do_feed_sitemap', 'xml_sitemap_load_template', 10, 1);
415
 
416
  // REWRITES
417
  add_filter('generate_rewrite_rules', 'xml_sitemap_rewrite');
424
  register_activation_hook( __FILE__, 'xml_sitemap_activate' );
425
  register_deactivation_hook( __FILE__, 'xml_sitemap_deactivate' );
426