phpcms——rss问题
phpcms中的rss功能有一些小问题,一是生成的链接过长,二是不能生成全站rss,只能是栏目级别
注:在自己直接输出的代码中发现如果标题内容含有特殊字符(必如:"&"符号)会出现生成的rss不能解析错误
1,如果只是解决链接太长,大部分订阅网站不能正常订阅问题,使用url规则进行转换应该就就可以了(没有测试过)
2,
<?php
include"db_config.php";
header("Content-type:text/xml;charset=gbk");
$rss="<?xml version=\"1.0\" encoding=\"gbk\"?>\r\n";
$rss.="<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\" >\r\n";
$rss.="<channel>\r\n";
$rss.="<title>xxxx社会经济研究所</title>\r\n";
$rss.="<link>http://www.zhuanxing.cn/</link>\r\n";
$rss.="<description><![CDATA[xxxx社会经济研究所全站文章订阅 ]]></description>\r\n";
$rss.="<language>GBK</language>\r\n";
$rss.="<webMaster>http://xxx.cn</webMaster> \r\n";
$rss.="<copyright>new sitexxxx</copyright> \r\n";
$rss.="<pubDate>".date("Y-m-d H:i:s")."</pubDate> \r\n\r\n";
echo$rss;
$db_sql="select id,title,url,description,thumb,aut,inputtime from `v9_news` where islink=0 order by id desc limit 50 ";
$db_result=mysqli_query($db_conn,$db_sql) or die("Err in query:".mysqli_error());
if (mysqli_num_rows($db_result)>0)
{
while($r=mysqli_fetch_assoc($db_result))
{
echo"\r\n<item>\r\n";
echo"<title>".htmlspecialchars($r['title'])."</title>\r\n";
echo"<link>"."<![CDATA[".htmlspecialchars($r['url'])."]]>"."</link>\r\n";
echo"<description>\r\n";
if($r['thumb']!=""){
echo"<![CDATA[<img src=".$r['thumb']." border='0' /><br />".htmlspecialchars($r['description'])."]]>";
}else{
echo"<![CDATA[".htmlspecialchars($r['description'])."]]>";
}
echo"</description>\r\n";
echo"<pubDate>".date('Y-m-d',$r['inputtime'])."</pubDate>\r\n";
echo"<guid><![CDATA[".$r['url']."]]></guid>\r\n";
echo"<author>".$r['aut']."</author>\r\n";
echo"</item>\r\n";
}
}
else
{
echo"no recoder";
}
mysqli_free_result($db_result);//释放结果集
mysqli_close($db_conn);//释放连接
$foot="\r\n\r\n</channel></rss>";
echo$foot;
?>
其他栏目页可以和上面的页面合并成一个文件
<?php
include"db_config.php";
header("Content-type:text/xml;charset=gbk");
$cate_catname;
$cate_image;
$cate_url;
$cate_description;
$ccatid;
$db_sqlx="select * from `v9_category` where catid=".intval($_GET["rssid"]);
$db_x=mysqli_query($db_conn,$db_sqlx) or die ("err in query 1:");
if ($db_catid=mysqli_fetch_assoc($db_x))
{
$ccatid=$db_catid['arrchildid'];
$cate_catname=$db_catid['catname'];
$cate_image=$db_catid['image'];
$cate_url=$db_catid['url'];
$cate_description=$db_catid['description'];
}
mysqli_free_result($db_x);//释放结果集
$rss="<?xml version=\"1.0\" encoding=\"gbk\"?>\r\n";
$rss.="<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\" >\r\n";
$rss.="<channel>\r\n";
$rss.="<title>".$cate_catname."</title>";
$rss.=" <link>http://xxx.cn/".$cate_url."</link>";
$rss.=" <description>".$cate_description."</description>";
$rss.="<image><url><![CDATA[".$cate_image." ]]></url></image>";
$rss.=" <language>GBK</language>";
$rss.="<webMaster>http://xxxxxx.cn</webMaster> ";
$rss.=" <copyright>xxxxx</copyright> ";
$rss.=" <pubDate>".date("Y-m-d H:i:s")."</pubDate> ";
echo$rss;
$db_sql="select id,title,url,description,thumb,aut,inputtime from `v9_news` where catid in (".$ccatid.") and islink=0 order by id desc limit 30 ";
$db_result=mysqli_query($db_conn,$db_sql) or die("Err in query 2:".$db_sql.mysqli_error());
if (mysqli_num_rows($db_result)>0)
{
while($r=mysqli_fetch_assoc($db_result))
{
echo"\r\n<item>\r\n";
echo"<title>".htmlspecialchars($r['title'])."</title>\r\n";
echo"<link>"."<![CDATA[".htmlspecialchars($r['url'])."]]>"."</link>\r\n";
echo"<description>\r\n";
if($r['thumb']!=""){
echo"<![CDATA[<img src=".$r['thumb']." border='0' /><br />".htmlspecialchars($r['description'])."]]>";
}else{
echo"<![CDATA[".htmlspecialchars($r['description'])."]]>";
}
echo"</description>\r\n";
echo"<pubDate>".date('Y-m-d',$r['inputtime'])."</pubDate>\r\n";
echo"<guid><![CDATA[".$r['url']."]]></guid>\r\n";
echo"<author>".$r['aut']."</author>\r\n";
echo"</item>\r\n";
}
}
else
{
echo"no recoder";
}
mysqli_free_result($db_result);//释放结果集
mysqli_close($db_conn);//释放连接
$foot="</channel></rss>";
echo$foot;
?>
如果要同时解决两个问题,我的方法是为此需要重新写这个页面
下面是简单的输出代码来完成,如果有人使用rss来重写,应该更好
这是列出所有分类的rss的方法,
{template "content","header_min"}
<div class="main">
<div >
<h6 class="title-2 f14 text-c">Rss订阅列表</h6>
<div class="content blue">
{pc:content action="category" catid="0" siteid="$this->siteid" order="listorder ASC"}
{loop $data $r}
<div class="color on blue_button"><a href="{APP_PATH}index.php?m=content&c=rss&rssid={$r[catid]}">{$r[catname]}<img src="{IMG_PATH}icon/rss.gif"></a></div>
<ul style="display:block">
{loop subcat($r[catid],0,0,$this->siteid) $v}
<li class="blue_button"><a href="{APP_PATH}index.php?m=content&c=rss&rssid={$v[catid]}">{$v[catname]} <img src="{IMG_PATH}icon/rss.gif"></a></li>
{/loop}
</ul>
{/loop}
{/pc}
</div>
</div>
</div>
<div class="clear"></div>
</div>
{template "content","footer"}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗