SEO页面没有在sitemap.xml中生成动态

时间:2013-09-04 05:13:05

标签: cakephp-2.0

我正在生成sitemap.xml,它生成的17个文件在网站上有链接意味着页面在页眉或页脚或链接,但我有50个SEO页面没有生成。我们在网站上没有任何链接(页眉,页脚和链接),它位于View / Pages文件夹中,方法位于PagesController中。我想在sitemap.xml中动态生成50个SEO页面。如何工作请尽快帮助任何身体。我正在做EErogh Generator.zip文件夹。

1 个答案:

答案 0 :(得分:2)

试试这个

public function seo_sitemap()
{
    $this->autoRender=false;
    $data = $this->Page->find('all');
    if(!empty($data))
    {
      $writer = new XMLWriter();
      $writer->openURI(WWW_ROOT.'/seo_pages_sitemap.xml');
      $writer->startDocument('1.0', 'UTF-8');
      $writer->setIndent(4);
      $writer->startElement('urlset');
      $writer->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
      $writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
      $writer->writeAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd');

      foreach ($data as $list)
      {

        $urls = SITEURL."/".$list['Page']['url'].".html";
        $lin=utf8_encode($urls);
        $url_date = date(DATE_W3C, strtotime($list['Page']['created']));
        $writer->startElement('url');
        $writer->writeElement('loc', $lin);
        $writer->writeElement('lastmod',trim($url_date));
        $writer->writeElement('changefreq', 'always');
        $writer->writeElement('priority', '0.8');
        $writer->endElement();

      }

        $writer->endElement();
        $writer->endDocument();
        echo SITEURL.'sitemap.xml created<br>';

    }


}