-
Notifications
You must be signed in to change notification settings - Fork 8
/
generatesitemap.php
executable file
·49 lines (45 loc) · 1.93 KB
/
generatesitemap.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
<?php
//Exit if not called in proper context
if (!defined('ABSPATH')) exit();
$args = array(
'post_type' => array('foxyshop_product'),
'post_status' => 'publish',
'numberposts' => -1
);
$products = get_posts($args);
header ("Content-Type:text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
foreach ($products as $product) {
echo '<url>'."\n";
echo '<loc>' . esc_url(get_bloginfo('wpurl') . '/' . FOXYSHOP_PRODUCTS_SLUG . '/' . htmlspecialchars($product->post_name)) . '/</loc>'."\n";
echo '<lastmod>' . esc_html(date('Y-m-d\TH:i:s+00:00',strtotime($product->post_modified))) . '</lastmod>'."\n";
echo '<changefreq>weekly</changefreq>'."\n";
echo '<priority>1.0</priority>'."\n";
echo '</url>'."\n";
}
$termchildren = get_terms('foxyshop_categories', 'hide_empty=0&hierarchical=0&orderby=name&order=ASC');
if ($termchildren) {
echo '<url>'."\n";
echo '<loc>' . esc_url(get_bloginfo('wpurl') . '/' . FOXYSHOP_PRODUCT_CATEGORY_SLUG) . '/</loc>'."\n";
echo '<lastmod>' . esc_html(date('Y-m-d\TH:i:s+00:00',time())) . '</lastmod>'."\n";
echo '<changefreq>weekly</changefreq>'."\n";
echo '<priority>1.0</priority>'."\n";
echo '</url>'."\n";
foreach ($termchildren as $child) {
echo '<url>'."\n";
echo '<loc>' . esc_url(get_term_link((int)$child->term_id, "foxyshop_categories")) . '</loc>'."\n";
echo '<lastmod>' . esc_html(date('Y-m-d\TH:i:s+00:00',time())) . '</lastmod>'."\n";
echo '<changefreq>weekly</changefreq>'."\n";
echo '<priority>1.0</priority>'."\n";
echo '</url>'."\n";
}
} else {
echo '<url>'."\n";
echo '<loc>' . esc_url(get_bloginfo('wpurl') . '/' . FOXYSHOP_PRODUCTS_SLUG) . '/</loc>'."\n";
echo '<lastmod>' . esc_html(date('Y-m-d\TH:i:s+00:00',time())) . '</lastmod>'."\n";
echo '<changefreq>weekly</changefreq>'."\n";
echo '<priority>1.0</priority>'."\n";
echo '</url>'."\n";
}
echo '</urlset>';