This repository has been archived by the owner on Nov 28, 2019. It is now read-only.
forked from TiagoLuisRE/WP-InstaSites
/
google-xml-sitemap.php
82 lines (78 loc) · 3.57 KB
/
google-xml-sitemap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Google XML Sitemap
*
* @author Cor van Noorloos
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* @link https://github.com/corvannoorloos/google-xml-sitemap
*
* @wordpress
* HiddenPlugin Name: Google XML Sitemap
* Plugin URI: https://github.com/corvannoorloos/google-xml-sitemap
* Description: Sitemaps are a way to tell Google about pages on your site we might not otherwise discover. In its simplest terms, a XML Sitemap—usually called Sitemap, with a capital S—is a list of the pages on your website. Creating and submitting a Sitemap helps make sure that Google knows about all the pages on your site, including URLs that may not be discoverable by Google's normal crawling process.
* Author: Cor van Noorloos
* Version: 0.1.1
* Author URI: http://corvannoorloos.com/
* (Bookt) The original file has been modified to output specific entries from BAPI seo data
*/
function google_sitemap() {
if ( ! preg_match( '/sitemap\.xml$/', $_SERVER['REQUEST_URI'] ) ) {
return;
}
global $wpdb;
$posts = $wpdb->get_results(
"SELECT ID, post_title, post_modified_gmt
FROM $wpdb->posts
WHERE post_status = 'publish'
AND post_type <> 'nav_menu_item'
AND post_name <> 'hello-world'
AND post_password = ''
ORDER BY post_type DESC, post_modified DESC
LIMIT 50000"
);
header( "HTTP/1.1 200 OK" );
header( 'X-Robots-Tag: noindex, follow', true );
header( 'Content-Type: text/xml' );
echo '<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . '"?>' . "\n";
echo '<!-- generator="' . home_url( '/' ) . '" -->' . "\n";
$xml = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";
$xml .= "\t<url>" . "\n";
$xml .= "\t\t<loc>" . home_url( '/' ) . "</loc>\n";
$xml .= "\t\t<lastmod>" . mysql2date( 'Y-m-d\TH:i:s+00:00', get_lastpostmodified( 'GMT' ), false ) . "</lastmod>\n";
$xml .= "\t\t<changefreq>" . 'daily' . "</changefreq>\n";
$xml .= "\t\t<priority>" . '1' . "</priority>\n";
$xml .= "\t</url>" . "\n";
foreach ( $posts as $post ) {
if ( $post->ID == get_option( 'page_on_front' ) )
continue;
if ( ! empty( $post->post_title ) ) {
// prevent outputing detail screens which can be determined by seeing if the post has a meta bapikey
$bapikey = get_post_meta($post->ID, "bapikey", true);
if (empty($bapikey)) {
$xml .= "\t<url>\n";
$xml .= "\t\t<loc>" . get_permalink( $post->ID ) . "</loc>\n";
$xml .= "\t\t<lastmod>" . mysql2date( 'Y-m-d\TH:i:s+00:00', $post->post_modified_gmt, false ) . "</lastmod>\n";
$xml .= "\t\t<changefreq>" . 'weekly' . "</changefreq>\n";
$xml .= "\t\t<priority>" . '0.8' . "</priority>\n";
$xml .= "\t</url>\n";
}
}
}
// now output the pages from bapi seo data
global $bapisync;
global $bapi_all_options;
foreach ($bapisync->seodata as $seo) {
if (!empty($seo["entity"]) && !empty($seo["pkid"])) {
$turl = BAPISync::cleanurl($seo["DetailURL"]);
$xml .= "\t<url>\n";
$xml .= "\t\t<loc>" . $bapi_all_options['bapi_site_cdn_domain'] . $turl . "</loc>\n";
$xml .= "\t\t<lastmod>" . mysql2date( 'Y-m-d\TH:i:s+00:00', $seo["ModifiedOn"]["LongDateTime"], false ) . "</lastmod>\n";
$xml .= "\t\t<changefreq>" . 'weekly' . "</changefreq>\n";
$xml .= "\t\t<priority>" . '0.8' . "</priority>\n";
$xml .= "\t</url>\n";
}
}
$xml .= '</urlset>';
echo ( "$xml" );
exit();
}