Create rss feed is simple and easy using php and mysqli, feed will dramatically increase your website traffic, feed will keep track of your visitors directly presenting your web content.
RSS Feed Format
Here is the valid rss feed format, we will be using php and mysqli to pull out post from our existing database.
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> <rss version="2.0"> <channel> <title>₦airaland Forum- Offical Script</title> <link>https://demo.christianity24.org</link> <description>₦airaland Forum- Offical Script Nigerian Forum</description><language>en-En</language><webMaster> unduworldofliving@gmail.com</webMaster> <item> <title>How to Nairaland Forum Script</title> <link>https://demo.christianity24.org/50/how-to-nairaland-forum-script.html</link> <description><![CDATA[<b> Install Script</b>]]></description> <pubDate>Tue, 24 Apr 2018 22:45:00 -0400</pubDate> </item> <item> <title>Version 3.5 Released</title> <link>https://demo.christianity24.org/49/version-3-5-released.html</link> <description><![CDATA[<b>Version 3.5]]></description> <pubDate>Tue, 24 Apr 2018 22:40:18 -0400</pubDate> </item> <item> <title>Emojis are supported on iOS, Android, macOS, Windows, Linux and ChromeOS.</title> <link>https://demo.christianity24.org/48/emojis-are-supported-on-ios-android-macos-windows-linux-and-chromeos-.html</link> <description><![CDATA[Emojis are supported on iOS, Android, macOS, Windows, Linux and ChromeOS. Copy and paste emojis for Twitter, Facebook, Slack, Instagram, Snapchat, Slack, GitHub, Instagram, WhatsApp and more. Use Emoji Cl****ic on older systems.]]></description> <pubDate>Tue, 24 Apr 2018 22:35:34 -0400</pubDate> </item> <item> <title>Version 3.0 Released</title> <link>https://demo.christianity24.org/47/version-3-0-released.html</link> <description><![CDATA[Version 3.0]]></description> <pubDate>Tue, 24 Apr 2018 22:34:01 -0400</pubDate> </item> </channel></rss>
How to implement Rss using php
- First create a feed.php file
- Copy the following code to feed.php and save it
<?php require_once ('config.php'); $page_title=TITLE; $site_url=URL; $site_email=EMAIL; echo '<?xml version="1.0" encoding="utf-8" standalone="yes" ?><rss version="2.0"><channel> <title>'.$page_title.'</title> <link>'.$site_url.'</link> <description>'.$page_title.' Nigerian Forum</description> <language>en-En</language> <webMaster> '.$site_email.'</webMaster>'; header("Content-Type: application/xml"); require 'incfiles/bbparser.php'; // phpbb code parser $sql = "SELECT * FROM `topics` ORDER BY topic_id DESC "; $query = $db->query($sql); while($row = mysqli_fetch_assoc($query)) { $title=$row['title']; $link=$row['link']; $tid = $row["topic_id"]; $date = date("r", $row["time"]); $mmessage = $row["content_text"]; $bbcodes = new bbParser(); $message = $bbcodes->getHtml($mmessage); $link = $site_url . '/' . $tid . '/' . $link; //redirect="$topic_id/$link"; // create friendly seo post link(url) echo '<item> <title>'.$title.'</title> <link>'.$link.'</link> <description><![CDATA['.$message.']]></description> <pubDate>'.$date.'</pubDate> </item>'; } echo '</channel></rss>'; ?>
- All done, feed is ready to share with friends and users
Database Structure
-- phpMyAdmin SQL Dump -- version 4.7.0 -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 -- Generation Time: May 01, 2018 at 05:07 PM -- Server version: 10.1.25-MariaDB -- PHP Version: 7.1.7 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; -- -- Database: `forum` -- -- -------------------------------------------------------- -- -- Table structure for table `topics` -- CREATE TABLE `topics` ( `topic_id` int(11) NOT NULL, `post_type` varchar(30) NOT NULL, `title` varchar(100) NOT NULL, `link` varchar(100) NOT NULL, `content_text` text NOT NULL, `tags` varchar(100) NOT NULL, `asked` varchar(50) NOT NULL, `user_id_fk` int(11) NOT NULL, `board_id_fk` int(11) NOT NULL, `created` varchar(30) NOT NULL, `status` int(11) NOT NULL, `today` varchar(20) NOT NULL, `month` varchar(30) NOT NULL, `time` varchar(100) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for dumped tables -- -- -- Indexes for table `topics` -- ALTER TABLE `topics` ADD PRIMARY KEY (`topic_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `topics` -- ALTER TABLE `topics` MODIFY `topic_id` int(11) NOT NULL AUTO_INCREMENT;COMMIT;
Database Connection
Here is your db connection
Here is your db connection
<?php //db configuraton details session_start(); define('DB_SERVER', 'localhost'); define('DB_USERNAME', 'root'); define('DB_PASSWORD', ''); define('DB_DATABASE', 'forum'); $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); //Connect and select the database
define('URL', 'https://demo.christianity24.org'); // set website url define('TITLE', 'Nairaland Official Script'); define('DSC', 'Nairaland Official Script');
define('EMAIL', 'unduworldofliving@gmail.com'); // define email
?>
https://demo.christianity24.org/feed
Please if you have any question comment below.
Don’t forget to share with friends and forums
Hit me with a comment!