Hello everyone!
I want to share a piece of code, 'few' or 'most' people usually have issues creating--->A dynamic rss feed.
Dynamic means-- fetching articles from the database.
Instead of you updating the rss manually.
Like a month back, some guy was here having issues with it, I don't know if I helped with his issue, because I never really ran the codes on my machine.
Until one day I decided to try, and I discovered why he had issues.
Now I'll be using Mysqli queries first,
Then I'll put up the Mysql query syntax for those still using mysql in a comment(//) below the mysqli syntax.
Ok to cut the story story...
Here's the code.
PHP Code:
<?php
<?php
//first include your database connection //setup
//lets call it include_database.php
Include 'include_database.php';
//now let's set the header content to xml
//because we won't be saving the file with
//the extension .xml instead it will be .php
//That is dynamic_rss.php
header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>'."
<rss version='2.0'>
<channel>
<title>Website Feed</title>
<description>Dynamic Website Rss Feed</description>
<link>LinkToWebsiteRss.com</link>";
$query = "SELECT * FROM `articles` LIMIT 30";
//you can change your limit values!
$result = mysqli_query($dbconn, $query);
//if u are still using mysql
//do this $result = mysql_query($query)
//remove the 'i' in the mysqli
While($row = mysqli_fetch_array($result))
{
echo ' <item><title>'.$row["title"]. '</title>
<description><![CDATA['.$row["article_story"].']]></description>
<link>http://link_to_the_full_article_story.com</link>
<pubDate>date of article</pubDate></item>';
}
echo '</channel>';
echo '</rss>';
?> ?>
I hope this helps!
Feel free to contact me if you have any issues.
Thank you :)
{{comment.anon_name ?? comment.full_name}}
{{timeAgo(comment.date_added)}}
{{comment.body}}
{{subComment.anon_name ?? subComment.full_name}}
{{timeAgo(subComment.date_added)}}
{{subComment.body}}