RSS 生成器

Avatar of Chris Coyier
Chris Coyier

您需要一个 MySQL 数据库,其中包含一个名为 `rss_feed` 的表。该表中有 3 列:**项目标题**(用户将看到的项目名称)、**项目链接**(包含项目的页面位置)和**描述**(说明供稿内容)。将文件放入名为 **feed** 的文件夹中,您的供稿将可在 yoursite.com/feed 处获取。

请记住为您的特定供稿更改供稿标题、链接和图像。

<?php
   
   // Connect to database... (you'll need to create this yourself)
   require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php';

   // Run query...
   $getFeed = mysql_query("SELECT *
                           FROM `rss_feed`
                           ORDER BY `time` DESC
                           ")or die(mysql_error());

   // Output XML (RSS)
    echo '<?xml version="1.0" encoding="ISO-8859-1" ?>
          <rss version="2.0">
                <channel>
                        <title>Your RSS Title</title>
                        <link>http://the_location_of_your_feed/feed</link>
                        <description>Description of your Feed</description>
                        <language>English</language>
                        <image>
                                <title>website Logo</title>
                                <url></url>
                                <link>Link to image</link>
                                <width>width</width>
                                <height>height</height>
                        </image>';
						while($rssFeed = mysql_fetch_array($getFeed)) {
        					 echo '<item>',
					              '<title>', $rssFeed['item_title']</title>',
					              '<link>', $rssFeed['link'], '</link>',
					              '<description><![CDATA[ ,$rssFeed['description'],']]></description>
								   </item>';

 						}
				echo '</channel>
        </rss>';

?>