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"}

posted @ 2011-08-18 15:34  fsl  阅读(1918)  评论(1编辑  收藏  举报