[经验]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模板文件,文件代码如下:
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的模板代码进行修改:
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>wlxs[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}
/********调用单页的代码********/
{dede:sql sql='Select * from dede_sgpage order by uptime asc limit 48'}
<item>
<link>***/[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>***/[field:filename/]</guid>
<description><![CDATA[[field:body function='html2text(@me)'/]]]></description>
</item>
{/dede:sql}
/********调用单页的代码********/
</channel>
</rss>
仅供大家学习使用,希望对你有所帮助!