Here is the code folks for getting an RSS feed on your classifieds site. Don't forget to set up your include files to call database settings (e.g. include 'inc/rssconfig.php'; etc. marked in RED)
My pages are in the format
http://www.mysite.com/motor_bmw-o6614-en.html so change accordingly marked in Green.
Hope this makes sense.
Rgds,
S
<?
include 'inc/rssconfig.php';
include 'inc/rssopen.php';// ... do something like insert or select, etc
// prepare HTML text for use as UTF-8 character data in XML
function cleanText($intext) {
return utf8_encode(
htmlspecialchars(
stripslashes($intext)));
}
// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=utf-8");
// store items from the database in the $result1 array
mysql_select_db($dbname);
$query1 = "select v_title, v_descr, link_id, hw_added from ec4_ad order by hw_added DESC limit 25";
$result1 = mysql_query($query1);
$phpversion = phpversion();
// display RSS 2.0 channel information
ECHO <<<END
<rss version="2.0">
<channel>
<title>Your Site Classifieds</title>
<link>
http://www.yoursite.com</link>
<description>Your Site Classifieds</description>
<copyright>Copyright (c) 2007 Your Site Classifieds</copyright>
<language>en-us</language>
<docs>
http://backend.userland.com/rss </docs>
<generator>PHP/$phpversion</generator>
<image>
<url>
http://www.yoursite.com/Images/logo.gif</url>
<link>
http://www.yoursite.com</link>
<width>140</width>
<height>60</height>
<title>Your Site Classifieds</title>
</image>
END;
// loop through the array pulling database fields for each item
//for ($i = 0; $i < mysql_num_rows($result1); $i++) {
// @$row = mysql_fetch_array($result1);
//$title = "".cleanText($row["v_title"])."";
//$link = "
http://www.yoursite.com/".cleanText($row["v_title"])."-
0".cleanText($row["link_id"]).".html ";
//$description = cleanText($row["v_descr"]);
for ($i = 0; $i < mysql_num_rows($result1); $i++) {
@$row = mysql_fetch_array($result1);
$title = "".cleanText($row["v_title"])."";
$link = "
http://www.yoursite.com/".preg_replace("~ ~","_",cleanText($row["v_title"])."-
o".cleanText($row["link_id"]))."-
en".".html";
$description = cleanText($row["v_descr"]);
//Replace Ugly HTML that got into the Knowledgebase with nothing
$desc_replace = array("<H3> </H3>", "<P> </P>", );
$desc_replace_with = array("", "", "");
$desc_temp = str_replace($desc_replace, $desc_replace_with, $description);
//Now clean the HTML
$mydescription = cleanText($desc_temp);
$pubDate = date("r", strtotime($row["hw_added"]));
// display an item
ECHO <<<END
<item>
<title>$title</title>
<link>$link</link>
<description>$description...
For the entire advert, please click on title above!</description>
<pubDate>$pubDate</pubDate>
<guid isPermaLink="false">$guid</guid>
</item>
END;
}
ECHO <<<END
</channel>
</rss>
END;
include 'inc/rssclose.php';?>
Information on the three files also needed here
These 3 files are used to hold PHP Database Connection, Open and Database Close configuration. The Main file in the RSS Sticky calls these files to find out your database settings and the close and open php files closes or opens the database.
The include is a command to call these files at the start and finish. The files are located in the inc folder but you can store these 3 files anywhere you wish.
include 'yourfoldernamewhereyouhavethefilesstore d\rssconfig.php' etc.
Follow these steps below to create these 3 files.
1. Type/Copy the following into a php file using either notepad/frontpage/dreamweaver etc. and save it as rssclose.php
<?php
mysql_close($conn);
?>
2. Type/Copy the following into a php file using either notepad/frontpage/dreamweaver etc. Edit the parts below with your own Database Settings and save it as rssconfig.php
<?php
$dbhost = 'Enter your DBHost Address Here';
$dbuser = 'Enter your DB Username Here';
$dbpass = 'Enter your DB username Password Here';
$dbname = 'Enter your Database Name Here';
$dbSettings["host"] = "Enter your DBHost Address Here";
$dbSettings["user"] = "Enter your DB Username Here";
$dbSettings["password"] = "Enter your DB username Password Here";
$dbSettings["name"] = "Enter your Database Name Here";
?>
3. Type/Copy the following into a php file using either notepad/frontpage/dreamweaver etc. and save it as rssopen.php
<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>