Generate RSS feeds for your website
04/03/10
Generate RSS feeds for your website
RSS newsfeeds and product feeds provide a variety of opportunities for increasing traffic to your website. Publishing your own feed is a great way to cut through the clutter of email spam and get your message directly to your target market. Interested parties can subscribe your RSS channel using common Email clients like Outlook. There are also many RSS readers available for Iphones or other smart phones.
RSS slowly becomes one of the important online marketing / SEO tasks.
Provided you already have an online product catalogue. Here is simple PHP code to use to generate a RSS feed:
PHP: | <?php |
| function xmlentities($str) |
| { |
| $xml = array('"','&','&','<','>',' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ'); |
| $html = array('"','&','&','<','>',' ','¡','¢','£','¤','¥','¦','§','¨','©','ª','«','¬','­','®','¯','°','±','²','³','´','µ','¶','·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','×','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú','û','ü','ý','þ','ÿ'); |
| |
| $str = str_replace($html,$xml,$str); |
| |
| return $str; |
| } |
| |
| $pro = DB_DataObject::factory('Product'); |
| $pro->find(); |
| $xml ='<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/"> |
| <channel> |
| <title>Water Coolers from Wenlock Water coolers Ltd</title> |
| <link>http://www.wenlockwatercoolers.co.uk/rss.php</link> |
| <description>Water Coolers supplier - Wenlock Water coolers, Shropshire UK. We sell and rent water coolers to Business, Education and home users all over the UK</description> |
| <language>en-GB</language> |
| <docs>http://backend.userland.com/rss</docs> |
| '; |
| while($pro->fetch()) |
| { |
| $catName = $categoryArray[$pro->category]; |
| $xml .= "<item> |
| <title>". xmlentities(htmlentities(stripSlashes("$pro->name"))) . "</title>\n"; |
| $xml .= "<link>http://www.wenlockwatercoolers.co.uk/index.php?product_id=$product->id</link>"; |
| $xml .="<category domain='main'>". stripSlashes($categoryname_Name). "</category>"; |
| $xml .="<description>"; |
| $xml .= xmlentities(htmlentities(stripSlashes($pro->detail) )); |
| $xml .="</description> |
| <content:encoded> |
| <![CDATA[ |
| <table> |
| "; |
| |
| |
| } |
| $xml .='</table> |
| <br/>'; |
| $xml .="]]></content:encoded> |
| </item> |
| "; |
| |
| |
| } |
| |
| $xml .="</channel> |
| </rss> "; |
| header("Content-Type: application/xml; charset=utf-81"); |
| echo $xml; |
| ?> |
To test it, you can type in the URL to the php file in your IE to validate the XML.
You can use a RSS viewer to view the data of your deed:
http://www.netimechannel.com/OnlineRssViewer/
Trackback address for this post:
https://www.sparkcomputing.co.uk/blogs/htsrv/trackback.php?tb_id=59
Trackbacks, Pingbacks:
|
|