其实很简单,照着格式查询数据库,然后再输出拼接即可!
<?php // +---------------------------------------------------------------------- // | JiZhiCMS { 极致CMS,给您极致的建站体验 } // +---------------------------------------------------------------------- // | Copyright (c) 2018-2099 http://www.jizhicms.com All rights reserved. // +---------------------------------------------------------------------- // | Author: 留恋风 <2581047041@qq.com> // +---------------------------------------------------------------------- // | Date:2020/04/11 // +---------------------------------------------------------------------- namespace Home\plugins; use Home\c\CommonController; class IndexController extends CommonController { function rss(){ $item = ''; //栏目item foreach($this->classtypedata as $v){ if($v['isshow']==1){ $item .= '<item> <title><![CDATA[ '.$v['classname'].' ]]></title> <link>'.$v['url'].'</link> <description><![CDATA[ '.$v['description'].' ]]></description> <source>'.$this->webconf['web_name'].'</source> <pubDate>'.date("D, d M Y H:i:s ", time()) . "GMT".'</pubDate> </item>'; } } //文章item $article = M('article')->findAll(['isshow'=>1]); foreach($article as $v){ $v['url'] = gourl($v,$v['htmlurl']); $item .= '<item> <title><![CDATA[ '.$v['title'].' ]]></title> <link>'.$v['url'].'</link> <description><![CDATA[ '.$v['description'].' ]]></description> <source>'.$this->webconf['web_name'].'</source> <pubDate>'.date("D, d M Y H:i:s ", time()) . "GMT".'</pubDate> </item>'; } //商品item $product = M('product')->findAll(['isshow'=>1]); foreach($product as $v){ $v['url'] = gourl($v,$v['htmlurl']); $item .= '<item> <title><![CDATA[ '.$v['title'].' ]]></title> <link>'.$v['url'].'</link> <description><![CDATA[ '.$v['description'].' ]]></description> <source>'.$this->webconf['web_name'].'</source> <pubDate>'.date("D, d M Y H:i:s ", time()) . "GMT".'</pubDate> </item>'; } $xml = '<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <title>'.$this->webconf['web_name'].'</title> <description>'.$this->webconf['web_desc'].'</description> <link>'.get_domain().'</link> <generator>Rss Powered By jizhicms</generator> <image> <url>'.get_domain().'/'.$this->webconf['web_logo'].'</url> <title>'.$this->webconf['web_name'].'</title> <link>'.get_domain().'</link> </image> '.$item.' </channel> </rss>'; header("Content-type:application/xml"); echo $xml; } }