RSS订阅概述
织梦CMS内置了RSS订阅功能,支持按栏目输出XML格式的内容摘要。RSS(Really Simple Syndication)允许用户通过RSS阅读器订阅网站更新,也常用于站群内容同步和搜索引擎收录。
一、织梦CMS默认RSS路径
全站RSS: /plus/rss.php 按栏目RSS: /plus/rss.php?tid=栏目ID 示例: 新闻栏目RSS: /plus/rss.php?tid=3 产品栏目RSS: /plus/rss.php?tid=5
二、在栏目页添加RSS订阅链接
<!-- 在栏目模板header中添加 -->
<link rel="alternate" type="application/rss+xml"
title="{dede:field.typename/} RSS订阅"
href="{dede:global.cfg_cmspath/}/plus/rss.php?tid={dede:field.id/}">
<!-- 在页面中显示RSS图标和链接 -->
<a href="/plus/rss.php?tid={dede:field.id/}" class="rss-link">
<img src="/images/rss.png" alt="RSS订阅">
订阅本栏目
</a>
三、自定义RSS模板
织梦CMS的RSS模板位于 templets/plus/rss.htm,可以自定义输出格式:
<?xml version="1.0" encoding="{dede:global.cfg_soft_lang/}"?>
<rss version="2.0">
<channel>
<title>{dede:global.cfg_webname/}</title>
<link>{dede:global.cfg_basehost/}</link>
<description>{dede:global.cfg_description/}</description>
<language>zh-cn</language>
{dede:arclist typeid='栏目ID' row='20' orderby='pubdate'}
<item>
<title><![CDATA[[field:title/]]]></title>
<link>[field:arcurl/]</link>
<description><![CDATA[[field:description/]]]></description>
<pubDate>[field:pubdate function="MyDate('r',@me)"/]</pubDate>
<guid>[field:arcurl/]</guid>
</item>
{/dede:arclist}
</channel>
</rss>
四、通过RSS实现站群内容同步
主站定时抓取子站RSS并导入文章:
<?php
require_once(dirname(__FILE__)."/include/common.inc.php");
$rss_url='http://子站域名/plus/rss.php?tid=3';
$rss=simplexml_load_file($rss_url);
foreach($rss->channel->item as $item){
$title=addslashes((string)$item->title);
$link=(string)$item->link;
$desc=addslashes((string)$item->description);
$pubdate=strtotime((string)$item->pubDate);
// 检查是否已存在(通过标题判断)
$check=$dsql->GetOne("SELECT id FROM dede_archives WHERE title='{$title}'");
if(!$check){
// 插入新文章
$dsql->ExecuteNoneQuery(
"INSERT INTO dede_archives (typeid,title,pubdate,senddate,description)
VALUES (目标栏目ID,'{$title}',{$pubdate},{$pubdate},'{$desc}')"
);
}
}
?>
五、向搜索引擎提交RSS
将RSS地址提交到搜索引擎加快收录:
<!-- 百度站长平台提交RSS sitemap -->
<!-- 在robots.txt中添加 -->
Sitemap: http://你的域名/plus/rss.php?tid=3
<!-- 使用百度主动推送API -->
<?php
$urls=array(
'http://你的域名/plus/rss.php?tid=3',
'http://你的域名/plus/rss.php?tid=5',
);
$api='http://data.zz.baidu.com/urls?site=你的域名&token=你的token';
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("\n", $urls));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
curl_exec($ch);
curl_close($ch);
?>
六、常见问题
- RSS中文乱码:确保
cfg_soft_lang设置为utf-8或gb2312,与数据库编码一致 - RSS内容不完整:
rss.htm模板中需使用CDATA包裹内容避免XML解析错误 - 栏目RSS为空:检查栏目是否有已审核的文章(arcrank=0)
- 文章链接错误:确保
[field:arcurl/]返回完整URL,或设置cfg_basehost
SEO价值:RSS订阅内容会被搜索引擎快速抓取。维护好各栏目的RSS输出,可以加快新发布内容的收录速度。建议为每个重点栏目都提供独立的RSS订阅地址。