使用 Zend_Navigation 进行图像站点地图
我使用 Zend_Navigation 生成站点地图,我想将图像添加到此站点地图,现在我不知道如何完成此操作,我使用以下(工作)代码来生成站点地图
foreach($sitemapItems as $item)
{
$newSite = new Zend_Navigation_Page_Uri();
$newSite->uri = 'http://' . $_SERVER['HTTP_HOST'] . $item->getSpeakingUrl();
$newSite->lastmod = $item->getUpdatedAt();
$newSite->changefreq = 'weekly';
$this->_navigation->addPage($newSite);
}
$this->view->navigation($this->_navigation);
$this->view->navigation()->sitemap()->setFormatOutput(true);
输出如下:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://test.dev/pictures/site-28.html</loc>
<lastmod>2010-03-11T17:47:30+01:00</lastmod>
<changefreq>weekly</changefreq>
</url>
....
我需要以下输出 网址部分
<image:image>
<image:loc>http://example.com/image.jpg</image:loc>
</image:image>
我尝试设置的
$newSite->image = URI
,但它不起作用,我也尝试通过添加自定义属性
$newSite->__set('image', array('loc' => URI));
有人知道我想要的是否可能吗?我在文档或网络中找不到任何内容...
感谢您的宝贵时间, 多米尼克
I generate a Sitemap using Zend_Navigation and i wanted to add images to this sitemap, now i got no Idea how to get this done, i use following (working) code to generate the sitemap
foreach($sitemapItems as $item)
{
$newSite = new Zend_Navigation_Page_Uri();
$newSite->uri = 'http://' . $_SERVER['HTTP_HOST'] . $item->getSpeakingUrl();
$newSite->lastmod = $item->getUpdatedAt();
$newSite->changefreq = 'weekly';
$this->_navigation->addPage($newSite);
}
$this->view->navigation($this->_navigation);
$this->view->navigation()->sitemap()->setFormatOutput(true);
The Output is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://test.dev/pictures/site-28.html</loc>
<lastmod>2010-03-11T17:47:30+01:00</lastmod>
<changefreq>weekly</changefreq>
</url>
....
I need the following Output inside the Url part
<image:image>
<image:loc>http://example.com/image.jpg</image:loc>
</image:image>
i tried to just set
$newSite->image = URI
but it didnt work also i tried to add custom attribute via
$newSite->__set('image', array('loc' => URI));
Does anyone know if what i want is even possible ? i cant find anything in the docs or web...
Thanks for your time,
Dominik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,首先您需要做的是扩展 Zend_Navigation_Page_Uri 并将您的图像变量添加到其中,如下所示:
将此类添加到library/Mylib/NavPageUriImage.php。
为了使其可用,您需要注册名称空间(我喜欢在 bootstrap 中注册名称空间,但也可以从 app.ini 完成),因此在您的 bootstrap 类中添加以下内容:
然后在您的控制器中您现在可以使用:
不推荐以下内容,您需要扩展您自己的导航助手并使用它(我现在没有时间玩它)全部添加您自己的 imageValidator
然后在 Library/zend/ 中view/helper/navigation/sitemap.php 添加以下行(在添加优先级元素 if 语句下,我的在 443 处结束,所以我在 444 处添加了此行):
Oki so first what you need to do is extend Zend_Navigation_Page_Uri and add you're image var to it smth like below :
Add this class to library/Mylib/NavPageUriImage.php.
To make it usable you need to register the namespace ( i like to register my namespaces at bootstrap but it can be done from app.ini too ) so in you're bootstrap class add the following :
Then in you're controller you can now use :
THE FOLLOWING IS NOT RECOMENDED , YOU NEED TO EXTEND YOU'RE OWN NAVIGATION HELPER AND USE THAT ( i just don't have the time to play with it now ) ALLSO ADD YOU'RE OWN imageValidator
And then in library/zend/view/helper/navigation/sitemap.php add the following lines ( under the add priority element if statement , mine ends at 443 so i added this at 444 ) :