Zen-Cart的RSS页面制作

转载出处:http://blog.fashion-century.com/archives/76

 

      RSS(Really Simple Syndication ) 直译过来就是真正简单的聚合,主要是提供给浏览者订阅当前站点的最新内容。这样订阅者不需要直接访问该站点就可以获取站点最新的更新内容,是一种比较有效的SEO推广方法。

      RSS一般都是采用XML格式来编写的,大致格式如下:


<?xml version=/"1.0/"?>
<rss version=/"2.0/">
      <channel>
            <title>Thebagstores RSS</title>  /*RSS的标题*/
            <link>http://www.thebagstores.com/RSS.php</link>  /*站点的URL链接*/
            <description>Thebagstores RSS</description>  /*描述*/
            <language>en-us</language>  /*使用的语言*/
            <pubDate>$now</pubDate>  /*生成的时间*/
            <lastBuildDate>$now</lastBuildDate>  /*上次生成的时间*/
            <docs>http://someurl.com</docs>
            <managingEditor>sales@thebagstores.com</managingEditor>  /*填联系人邮箱*/
            <webMaster>sales@thebagstores.com</webMaster>  /*填联系人邮箱*/

            <item>

                  <title>这里是标题内容</title>

                  <link>这里填写的URL链接</link>

                  <description>这里是简要的描述(完整的内容也可,比如新闻)</description>

            </item>

                  。

                  。

                  。循环添加

                  。

                  。

                  <title>这里是标题内容</title>

                  <link>这里填写的URL链接</link>

                  <description>这里是简要的描述(完整的内容也可,比如新闻)</description>

            </item>

      </channel>

</rss>



      下面就附上一个Zen-Cart的Rss实例

      http://www.thebagstores.com/RSS.ph源码如下:


<?php
require("includes/application_top.php");//包含必须的文件
/*
 *设置urlShow
 */
function regexStr($str){
    $str = preg_replace("//s+/","-",$str);//没有空格了
    $str = preg_replace("/[^-/w]/", "",$str);//只保留-,数字或者字符,不区分大小写
    $str = preg_replace("/[-]{2,}/","-",$str);//2个以上的-都换成一个
    if(substr($str,0,1)=="-")//如果是开头是-,也去了
        $str = substr($str,1,strlen($str)-1);
    if(substr($str,strlen($str)-1,1)=="-")//如果是结尾是-,也去了
        $str = substr($str,0,strlen($str)-1);
    return $str;   
}

$now = date("D, d M Y H:i:s T");
$output = "<?xml version=/"1.0/"?>
            <rss version=/"2.0/">
                <channel>
                    <title>Thebagstores RSS</title>
                    <link>http://www.thebagstores.com/RSS.php</link>
                    <description>Thebagstores RSS</description>
                    <language>en-us</language>
                    <pubDate>$now</pubDate>
                    <lastBuildDate>$now</lastBuildDate>
                    <docs>http://someurl.com</docs>
                    <managingEditor>sales@thebagstores.com</managingEditor>
                    <webMaster>sales@thebagstores.com</webMaster>
            ";


//获取最新新闻
$sql = "select a1.article_id as aid,a1.news_article_name as title,a1.news_article_text as text,a2.news_date_added from zen_news_articles_text a1,zen_news_articles a2 where a1.article_id=a2.article_id order by a2.news_date_added desc limit 20;";
$result = $db->Execute($sql);
while(!$result->EOF){
    $aid = $result->fields["aid"];
    //echo $aid.'<br />';
    $title = $result->fields["title"];//取得新闻标题
    //echo $title.'<br />';
    $urlShow = regexStr($result->fields["title"]);//生成标题的urlShow
    //echo $urlShow.'<br />';
    $text = $result->fields["text"];//截取新闻内容
    //echo $text.'<br />';
   
    $output .= "<item><title>".htmlentities($title)."</title>
                    <link>".htmlentities("http://www.thebagstores.com/news/".$urlShow."-a-".$aid.".html")."</link>
                   
<description>".htmlentities(strip_tags($text))."</description>
                </item>";
    $result->MoveNext();               
}
$output .= "</channel></rss>";
echo $output;
?>

 

 

 

 

 

转载出处:http://blog.fashion-century.com/archives/76

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值