xml-sitemap-feed
Last commit date
readme.txt
16 years ago
template.php
16 years ago
xml-sitemap.php
16 years ago
template.php
72 lines
| 1 | <?php |
| 2 | /** |
| 3 | * XML Sitemap Feed Template 2.1 |
| 4 | **/ |
| 5 | |
| 6 | if (!empty($_SERVER['SCRIPT_FILENAME']) && 'feed-sitemap.php' == basename($_SERVER['SCRIPT_FILENAME'])) |
| 7 | die ('Please do not load this page directly. Thanks!'); |
| 8 | |
| 9 | header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); |
| 10 | $more = 1; |
| 11 | |
| 12 | $lastpostmodified = get_lastpostmodified('GMT'); |
| 13 | |
| 14 | $post_priority = 0.7; |
| 15 | $minpost_priority = 0.3; |
| 16 | $maxpost_priority = 0.9; |
| 17 | $page_priority = 0.6; |
| 18 | $frontpage_priority = 1.0; |
| 19 | |
| 20 | ?> |
| 21 | <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?> |
| 22 | <!-- generator="XML Sitemap Feed WordPress plugin/2.1" --> |
| 23 | <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 24 | xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" |
| 25 | xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
| 26 | <url> |
| 27 | <loc><?php bloginfo_rss('url') ?></loc> |
| 28 | <lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $lastpostmodified, false); ?></lastmod> |
| 29 | <changefreq>daily</changefreq> |
| 30 | <priority>1.0</priority> |
| 31 | </url> |
| 32 | <?php |
| 33 | |
| 34 | $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1000"); |
| 35 | |
| 36 | if ($post_ids) { |
| 37 | global $wp_query; |
| 38 | $wp_query->in_the_loop = true; |
| 39 | |
| 40 | while ( $next_posts = array_splice($post_ids, 0, 20) ) { |
| 41 | $where = "WHERE ID IN (".join(',', $next_posts).")"; |
| 42 | $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt DESC"); |
| 43 | foreach ($posts as $post) { |
| 44 | setup_postdata($post); |
| 45 | $post_modified_time = get_post_modified_time('Y-m-d H:i:s', true); |
| 46 | $priority_down = (($lastpostmodified - $post_modified_time) > 0) ? ($lastpostmodified - $post_modified_time)/10 : 0; |
| 47 | $priority_up = ($post->comment_count > 0) ? $post->comment_count/10 : 0; |
| 48 | $priority = $post_priority - $priority_down + $priority_up; |
| 49 | $priority = ( $priority > $maxpost_priority ) ? $maxpost_priority : $priority; |
| 50 | $priority = ( $priority < $minpost_priority ) ? $minpost_priority : $priority; |
| 51 | ?> |
| 52 | <url> |
| 53 | <loc><?php the_permalink_rss() ?></loc> |
| 54 | <lastmod><?php echo mysql2date('Y-m-d\TH:i:s+00:00', $post_modified_time, false) ?></lastmod> |
| 55 | <?php if($post->post_type == "page") { ?> |
| 56 | <changefreq>monthly</changefreq> |
| 57 | <priority>0.5</priority> |
| 58 | <?php } else { |
| 59 | if($post->comment_count > 0) { ?> |
| 60 | <changefreq>weekly</changefreq> |
| 61 | <?php } else { ?> |
| 62 | <changefreq>monthly</changefreq> |
| 63 | <?php } ?> |
| 64 | <priority><?php echo $priority ?></priority> |
| 65 | <?php //echo "<test>" . $post_priority . " - " . $priority_down . " + " . $priority_up . "</test>" ?> |
| 66 | <?php } ?> |
| 67 | </url> |
| 68 | <?php } |
| 69 | } |
| 70 | } ?> |
| 71 | </urlset> |
| 72 |