Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude List for Sitemap #5

Open
Gummibeer opened this issue Oct 7, 2014 · 0 comments
Open

exclude List for Sitemap #5

Gummibeer opened this issue Oct 7, 2014 · 0 comments

Comments

@Gummibeer
Copy link

I added another Var to exclude folders from the Sitemap, for example: slider, home-parts, search
And added the <lastmod> Attribute.

class Pico_Sitemap {
    private $is_sitemap;
    private $exclude;
public function __construct(){
    $this->is_sitemap = false;
    $this->exclude = array('home', 'slider', 'suche');
}
public function get_pages(&$pages, &$current_page, &$prev_page, &$next_page) {
    if($this->is_sitemap) {
        global $config;
        header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
        header('Content-Type: application/xml; charset=UTF-8');
        $xml = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
        foreach( $pages as $page ) {
            preg_match('/\/('.implode('|', $this->exclude).')\//', $page['url'].'/', $matches);
            if(empty($matches)) {
                $index = '';
                $date = '';
                $path = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'content'.DIRECTORY_SEPARATOR.str_ireplace($config['base_url'], '', $page['url']);
                if(is_dir($path)) { $index = 'index'; }
                $file = realpath($path.$index.'.md');
                if(file_exists($file)) { $date = date ("Y-m-d", filemtime($file)); }
                $xml .= '<url><loc>'.$page['url'].'</loc><lastmod>'.$date.'</lastmod></url>';
            }
        }   
        $xml .= '</urlset>';
        header('Content-Type: text/xml');
        die($xml);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant