Skip to main content
 Web开发网 » 站长学院 » 织梦教程

dede全站RSS订阅静态输出的办法

2020年09月12日7830百度已收录

这个网络上就是这么个有趣和多样,有人喜欢让RSS订阅自动更新,动态显示,这样可以省下部分力气。 

织梦DedeCMS自带Rss功能,在管理后台可以生成出一个Rss地图页面,默认是/data/rssmap.html,这个Html地图文件会告知用户每个栏目的rss订阅地址,这个功能很适合栏目及文章较多的网站,但不太适合文章页不多的小型站点

 

 今天我们就稍微修改一下,借用DEDE的单页文档功能,将RSS弄成静态输出,一切为了蜘蛛!

 

实现DedeCMS Rss全站静态输出的方法:

一、在CMS根目录下,新增rss.php文件,文件代码如下:

PHP代码

    

<?php    

require_once (dirname(__FILE__) . "/include/common.inc.php");    

require_once (DEDEINC."/arc.partview.class.php");    

$pv = new PartView();    

$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/default/rss.htm");    

header("Content-type:application/xml");    

$pv->Display();    

?>     

 

二、在默认模板目录(/templetes/default)中,新增rss.html模板文件,文件代码如下:

XML/HTML代码   

<?xml version="1.0" encoding="{dede:global.cfg_soft_lang /}" ?>      

<rss version="2.0">      

<channel>      

<title>RSS订阅-{dede:global.cfg_webname/}</title>      

<link>{dede:global.cfg_basehost/}</link>      

<description>{dede:global.cfg_description/}</description>      

<language>zh-cn</language>      

<generator>{dede:global.cfg_webname/}</generator>      

<webmaster>{dede:global.cfg_adminemail/}</webmaster>      

{dede:arclist row='100' col='1' titlelen='200' orderby='pubdate'}      

<item>      

<link>/[field:arcurl/]</link>      

<title><![CDATA[[field:title function='html2text(@me)'/]]]></title>      

<author>[field:writer/]</author>      

<category>[field:typename/]</category>      

<pubDate>[field:pubdate function='strftime("%a, %d %b %Y %H:%M:%S +0800",@me)'/]</pubDate>      

<guid>/[field:arcurl/]</guid>      

<description><![CDATA[[field:description function='html2text(@me)'/]]]></description>       

</item>      

{/dede:arclist}    

</channel>    

</rss>  

 

三、在后台——核心——频道模型——单页文档管理,增加一个单页面,“模板文件名”项中输入第2步中涉及的模板文件rss.htm,而“文件名”中输入未来Rss订阅地址,这里我就直接生成在CMS根目录下了。

 

四、更新一下缓存,并更新刚刚新增的单页面,即可看到全站性的RSS输出,以后很方便的就可以用各种RSS软件去登录Submit rss地址了。

 

因此,用单页发布产品信息会很普遍,可惜的是上面谈及的全站RSS静态输出的方法是无法提取单页的,所以我们还需要对rss.html的模板代码进行修改:

 

XML/HTML代码

    

<?xml version="1.0" encoding="{dede:global.cfg_soft_lang /}" ?>      

<rss version="2.0">      

<channel>      

<title>RSS订阅-{dede:global.cfg_webname/}</title>      

<link>{dede:global.cfg_basehost/}</link>      

<description>{dede:global.cfg_description/}</description>      

<language>zh-cn</language>      

<generator>{dede:global.cfg_webname/}</generator>      

<webmaster>{dede:global.cfg_adminemail/}</webmaster>      

{dede:arclist row='100' col='1' titlelen='200' orderby='pubdate'}      

<item>      

<link>http://www.wlxs.com.cn[field:arcurl/]</link>      

<title><![CDATA[[field:title function='html2text(@me)'/]]]></title>      

<author>[field:writer/]</author>      

<category>[field:typename/]</category>      

<pubDate>[field:pubdate function='strftime("%a, %d %b %Y %H:%M:%S +0800",@me)'/]</pubDate>      

<guid>http://www.***.com[field:arcurl/]</guid>      

<description><![CDATA[[field:description function='html2text(@me)'/]]]></description>       

</item>      

{/dede:arclist}    

/********调用单页的代码********/    

{dede:sql sql='Select * from dede_sgpage order by uptime asc limit 48'}      

<item>      

<link>http://www.***.com/[field:filename/]</link>      

<title><![CDATA[[field:title function='html2text(@me)'/]]]></title>      

<author></author>      

<category></category>      

<pubDate>[field:uptime function='strftime("%a, %d %b %Y %H:%M:%S +0800",@me)'/]</pubDate>      

<guid>http://www.***.com/[field:filename/]</guid>      

<description><![CDATA[[field:body function='html2text(@me)'/]]]></description>      

</item>      

{/dede:sql}    

/********调用单页的代码********/    

</channel>      

</rss>  


 

评论列表暂无评论
发表评论
微信