Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Google News Sitemap
- */
- define('DONOTCACHEPAGE', true);
- define('DONOTCACHEDB', true);
- define('DONOTCACHCEOBJECT', true);
- header("Content-type: text/xml");
- echo '<?xml version="1.0" encoding="UTF-8"?>
- <?xml-stylesheet type="text/xsl" href="https://www.racunalo.com/google-news-sitemap.xsl"?>';
- echo '
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">';
- $have_posts = false;
- $args_news_sitemap = array (
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'date_query' => array(
- 'after' => date('Y-m-d', strtotime('-2 days'))
- ),
- 'category__not_in' => array(1),
- 'showposts' => 100,
- 'post_status' => 'publish',
- 'post_type'=>'post',
- 'no_found_rows' => true,
- 'cache_results' => false,
- 'update_post_term_cache' => false,
- 'update_post_meta_cache' => false
- );
- $query_news_sitemap = new WP_Query($args_news_sitemap);
- if($query_news_sitemap->have_posts()):
- while($query_news_sitemap->have_posts()):
- $query_news_sitemap->the_post();
- $have_posts = true;
- echo '
- <url>';
- echo '
- <loc>';
- echo the_permalink();
- echo '</loc>';
- echo '
- <news:news>
- <news:publication>
- <news:name>Website.com</news:name>
- <news:language>en</news:language>
- </news:publication>
- <news:publication_date>';
- echo the_time('c');
- echo '</news:publication_date>
- <news:title>';
- echo the_title_attribute('echo=0');
- echo '</news:title>
- <news:keywords>News</news:keywords>
- </news:news>
- </url>
- ';
- endwhile;
- endif;
- if (!$have_posts):
- echo '<url>
- <loc>https://www.website.com/</loc>
- </url>';
- endif; wp_reset_query();
- echo '
- </urlset>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement