njdubois Posted May 18, 2015 Share Posted May 18, 2015 I'd like to enable visitors to follow my blog using rss. How would I do that using my custom developed blog written with php? Thanks!! Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted May 18, 2015 Share Posted May 18, 2015 (edited) I'll explain it as simple as can. Make a folder named feed and create an index.php file within or create a new php file anywhere you desire. first line would be header info to declare it's document type header("Content-Type: application/rss+xml; charset=UTF-8"); connect to your database perform a select query to database use LIMIT to return limited amount of results if there is a result larger than zero continue Adding the rss format code $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>'; $rssfeed .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'; $rssfeed .= '<channel>'; $rssfeed .= '<atom:link href="http://site.com/feed/" rel="self" type="application/rss+xml"/>'; $rssfeed .= '<title>Site.com latest feeds</title>'; $rssfeed .= '<link>http://site.com</link>'; $rssfeed .= '<description>This is the description of my site</description>'; $rssfeed .= '<language>en-us</language>'; $rssfeed .= "<copyright>Copyright (C) 2009-" .date('Y'). " Site.com</copyright>"; Now do a while loop on your results code within the loop $rssfeed .= "<item>"; $rssfeed .= "<title>" . $row['title'] . "</title>"; $rssfeed .= "<guid>" . $row['permalink'] . "</guid>"; $rssfeed .= "<description><![CDATA[ <p>". $row['description'] ."</p> ]]></description>"; $rssfeed .= "<link>" . $row['permalink'] ."</link>"; $rssfeed .= "<pubDate>" . $row['date'] . "</pubDate>"; $rssfeed .= "</item>"; end of while loop closing tags and echo out $rssfeed $rssfeed .= "</channel>"; $rssfeed .= "</rss>"; echo $rssfeed; Edited May 18, 2015 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
njdubois Posted June 15, 2015 Author Share Posted June 15, 2015 Thank you so much! I only have one question so yeah, you made it pretty simple! What would $row['permalink'] be? <a href="whatever.php">blah</a> or just the url whatever.php? Thanks!! Nick Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted June 16, 2015 Share Posted June 16, 2015 That would be link back to article in feed. guid and link Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.