{"id":81,"date":"2006-02-01T19:26:00","date_gmt":"2006-02-01T19:26:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=81"},"modified":"2006-02-01T19:26:00","modified_gmt":"2006-02-01T19:26:00","slug":"google-sitemap-php-classes-xml-generator","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=81","title":{"rendered":"Google Sitemap &#8211; PHP Classes &#8211; XML Generator"},"content":{"rendered":"<p>If you need some PHP classes to generate Google Sitemap XML, you come to the right page.<br \/>\n<textarea name=\"code\" class=\"php\"><br \/>\n<?php\n\/** \n* @author Son Nguyen\n* @since 1\/31\/2006\n* @package Framework.Visual\n* @subpackage Google\n*\/\nclass CGoogleSiteMapBase {\n private $mURLs;\n \/** constructor *\/\n function __construct() {\n\n }\n\n \/** comment *\/\n function addURL($pURL) {\n  $this->mURLs[] = $pURL;<br \/>\n }<\/p>\n<p> \/** comment *\/<br \/>\n function display() {<br \/>\n  $vOutput = &#8216;<?xml version=\"1.0\" encoding=\"UTF-8\"?>&#8216;;<br \/>\n  $vOutput .= &#8216;<urlset xmlns=\"http:\/\/www.google.com\/schemas\/sitemap\/0.84\">&#8216;;<br \/>\n  foreach ($this->mURLs AS $vOne) {<br \/>\n   $vOutput .= $vOne->display();<br \/>\n  } \/\/ rof<br \/>\n  $vOutput .= &#8216;<\/urlset>&#8216;;<br \/>\n  return $vOutput;<br \/>\n }<br \/>\n}<br \/>\n?><br \/>\n<\/textarea><\/p>\n<p>CGoogleSiteMapURL is the support class for CGoogleSiteMapBase<br \/>\n<textarea name=\"code\" class=\"php\"><br \/>\n<?php\n\/** https:\/\/www.google.com\/webmasters\/sitemaps\/docs\/en\/protocol.html\n* @author Son Nguyen\n* @since 1\/31\/2006\n* @package Framework.Visual\n* @subpackage Google\n*\/\nclass CGoogleSiteMapURL {\n private $mURL;\n private $mModified; \/\/ int\n private $mFreq;\n private $mPriority;\n \/** constructor *\/\n function __construct($pURL,$pMod=null,$pFreq=null,$pPriority=null) {\n  $this->mURL = $pURL;<br \/>\n  $this->mModified = $pMod;<br \/>\n  $this->mFreq = $pFreq;<br \/>\n  $this->mPriority = $pPriority;<br \/>\n }<\/p>\n<p> \/** comment *\/<br \/>\n function display() {<br \/>\n  $vURL = str_replace(&#8216;&#038;&#8217;,&#8217;&amp;&#8217;,$this->mURL);<br \/>\n  $vOutput = &#8216;<url><loc>&#8216;.$vURL.&#8217;<\/loc>&#8216;;<br \/>\n  if (!is_null($this->mModified)) {<br \/>\n   $vOutput .= &#8216;<lastmod>&#8216;.date(&#8216;Y-m-d&#8217;,$this->mModified).&#8217;<\/lastmod>&#8216;;<br \/>\n  } \/\/ fi<br \/>\n  if (!is_null($this->mFreq)) {<br \/>\n   $vOutput .= &#8216;<changefreq>&#8216;.$this->mFreq.&#8217;<\/changefreq>&#8216;;<br \/>\n  } \/\/ fi<br \/>\n  if (!is_null($this->mPriority)) {<br \/>\n   $vOutput .= &#8216;<priority>&#8216;.$this->mPriority.&#8217;<\/priority>&#8216;;<br \/>\n  } \/\/ fi<br \/>\n  $vOutput .= &#8216;<\/url>&#8216;;<br \/>\n  return $vOutput;<br \/>\n }<br \/>\n}<br \/>\n?><br \/>\n<\/textarea><\/p>\n<p>Sample Usage: init the class and add URLs to the base class and call display to generate the XML.<\/p>\n<p><textarea name=\"code\" class=\"php\"><br \/>\n$vMap = new CGoogleSiteMapBase();<br \/>\n$vMap->addURL(new CGoogleSiteMapURL(&#8216;http:\/\/www.adspeed.com\/index.php&#8217;));<br \/>\nHeader(&#8220;Content-Type: text\/xml&#8221;);<br \/>\necho ($vMap->display());<br \/>\n<\/textarea><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need some PHP classes to generate Google Sitemap XML, you come to the right page. &#8216;; $vOutput .= &#8216;&#8216;; foreach ($this->mURLs AS $vOne) { $vOutput .= $vOne->display(); } \/\/ rof $vOutput .= &#8216;&#8216;; return $vOutput; } } ?> CGoogleSiteMapURL is the support class for CGoogleSiteMapBase Sample Usage: init the class and add URLs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/81"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}