forked from FoxyCart/foxyshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generatesitemap.php
executable file
·49 lines (46 loc) · 2 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);
$write = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$write .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
foreach ($products as $product) {
$write .= '<url>'."\n";
$write .= '<loc>' . get_bloginfo('wpurl') . '/' . FOXYSHOP_PRODUCTS_SLUG . '/' . htmlspecialchars($product->post_name) . '/</loc>'."\n";
$write .= '<lastmod>' . date('Y-m-d\TH:i:s+00:00',strtotime($product->post_modified)) . '</lastmod>'."\n";
$write .= '<changefreq>weekly</changefreq>'."\n";
$write .= '<priority>1.0</priority>'."\n";
$write .= '</url>'."\n";
}
$termchildren = get_terms('foxyshop_categories', 'hide_empty=0&hierarchical=0&orderby=name&order=ASC');
if ($termchildren) {
$write .= '<url>'."\n";
$write .= '<loc>' . get_bloginfo('wpurl') . '/' . FOXYSHOP_PRODUCT_CATEGORY_SLUG . '/</loc>'."\n";
$write .= '<lastmod>' . date('Y-m-d\TH:i:s+00:00',time()) . '</lastmod>'."\n";
$write .= '<changefreq>weekly</changefreq>'."\n";
$write .= '<priority>1.0</priority>'."\n";
$write .= '</url>'."\n";
foreach ($termchildren as $child) {
$write .= '<url>'."\n";
$write .= '<loc>' . get_term_link((int)$child->term_id, "foxyshop_categories") . '</loc>'."\n";
$write .= '<lastmod>' . date('Y-m-d\TH:i:s+00:00',time()) . '</lastmod>'."\n";
$write .= '<changefreq>weekly</changefreq>'."\n";
$write .= '<priority>1.0</priority>'."\n";
$write .= '</url>'."\n";
}
} else {
$write .= '<url>'."\n";
$write .= '<loc>' . get_bloginfo('wpurl') . '/' . FOXYSHOP_PRODUCTS_SLUG . '/</loc>'."\n";
$write .= '<lastmod>' . date('Y-m-d\TH:i:s+00:00',time()) . '</lastmod>'."\n";
$write .= '<changefreq>weekly</changefreq>'."\n";
$write .= '<priority>1.0</priority>'."\n";
$write .= '</url>'."\n";
}
$write .= '</urlset>';
header ("Content-Type:text/xml");
echo $write;