php-sitemap-generator icon indicating copy to clipboard operation
php-sitemap-generator copied to clipboard

Retrieve the modified date and populate de sitemap

Open oblab opened this issue 3 years ago • 1 comments

I try to retrieve the <meta property="article:modified_time" content="" /> in my website to populate <lastmod> tag in the sitemap

In sitemap-generator.php, after :

libxml_use_internal_errors(true);
		$dom = new DOMDocument();
		@$dom->loadHTML($html);

I add this :

		$xp = new domxpath($dom);
			foreach ($xp->query("//meta[@property='article:modified_time']") as $el) {
				 $el->getAttribute("content");
			}

I'm a beginner in php, how can i add $el to the xml ? Also, i'd like to format the modified_time in Y-M-D thanks

oblab avatar Apr 14 '22 07:04 oblab

I found a solution with php command get_meta_tags :

foreach ($pages as $page) {		
		 $tags = get_meta_tags($page);	
		 $tag = $tags['date'];  //We get the "meta name "date" content
$xml .= "<url><loc>" . $page . "</loc>
            <lastmod>" . $tag . "</lastmod> //We add the date content
            <changefreq>" . $this->config['CHANGE_FREQUENCY'] . "</changefreq>
            <priority>" . $this->config['PRIORITY'] . "</priority></url>";
		}

oblab avatar Jun 06 '22 13:06 oblab