Metro_Sitemap::build_xml PHP Method

build_xml() public static method

Build XML for output to clean up the template file
public static build_xml ( $request = [] )
    public static function build_xml($request = array())
    {
        $year = $request['year'];
        $month = $request['month'];
        $day = $request['day'];
        if (false === $year && false === $month && false === $day) {
            $xml = self::build_root_sitemap_xml();
        } else {
            if ($year > 0 && $month > 0 && $day > 0) {
                $xml = self::build_individual_sitemap_xml($year, $month, $day);
            } else {
                /* Invalid options sent */
                return false;
            }
        }
        return $xml;
    }

Usage Example

<?php

if (!Metro_Sitemap::is_blog_public()) {
    wp_die(__('Sorry, this site is not public so sitemaps are not available.', 'msm-sitemap'), __('Sitemap Not Available', 'msm-sitemap'), array('response' => 404));
}
$req_year = isset($_GET['yyyy']) ? intval($_GET['yyyy']) : false;
$req_month = isset($_GET['mm']) ? intval($_GET['mm']) : false;
$req_day = isset($_GET['dd']) ? intval($_GET['dd']) : false;
header('Content-type: application/xml; charset=UTF-8');
$build_xml = Metro_Sitemap::build_xml(array('year' => $req_year, 'month' => $req_month, 'day' => $req_day));
if ($build_xml === false) {
    wp_die(__('Sorry, no sitemap available here.', 'msm-sitemap'));
} else {
    echo $build_xml;
}