RSS has become the standard technology for syndicating information to large audiences. Many people have something to say, but its finding the right audience for your voice that matters. A great place to start is by creating your own RSS feed and adding to it as often as you can.
In this article you’ll learn how to syndicate your own custom RSS feeds using PHP and MySQL. We’ll first learn how to create two database tables and then how to retrieve data from them which will be formatted into an RSS feed. Here’s an example of the completed RSS feed and a download link to the code. Let’s start by taking a look at how to create the MySQL database tables.
Creating the MySQL RSS Tables
An RSS feed consists of the main details for the feed, such as the title, description, url, image and so on. Next are the items, probably the most important parts of the feed. i.e. Different stories from a newspaper, posts from a blog and so on. Therefore, we will create two database tables, the first is called webref_rss_details, which contains the details for the feed and the second is called webref_rss_items, which contains all of the items. If you would like to get a better idea of the RSS structure you can take a look at The Anatomy of an RSS Feed, which is a previous article I wrote on the basics of the RSS structure.
In order to get started with the database tables, use the following code, which can be found in the webref_rss_details.sql file, to create the webref_rss_details table:
The following code, which can be found in the webref_rss_items.sql file, will create the webref_rss_items table:
Our first table, webref_rss_details, contains 10 columns, which are the id, title, description, link, language, image_title, image_url, image_link, image_width and image_height. Each of these columns are self-explainatory once you are familiar with the structure of an RSS feed, the non-rss related column is the id, which is used to represent the id for the row of data in the database. The second table, webref_rss_items, contains 4 columns, which include the id, title, description and link. In the example I’m linking to the home page of the current Web site, but this url would typically link to the location of the original text, such as a specific blog page where an entry has been posted. Now that we officially have the MySQL tables created, add the data that you want to syndicate, then proceed to the next section and take a look at how to construct a valid RSS 2.0 feed with PHP.
Advertisement
Creating a valid RSS 2.0 feed with PHP
Once the database tables are in place we’ll create three PHP files. The first is called index.php, which belongs in the root of our site directory, the second RSS.class.php, which belongs in a directory called classes and the third mysql_connet.php, which should be placed in a directory that is inaccessible to the outside world. For the purposes of this article I placed the sample file in the same directory as the RSS class. In the index.php file, start by adding a header that will configure the content type of the document as valid XML and choose the charset that you need. Next include the RSS class, instantiate the object and trigger a method called GetFeed. The GetFeed method will return the actual RSS feed once it has been constructed in the class, so perform an echo on the return value to write the data to the index file.
Parsing Atom Feeds using XPath Atom has become a very popular way to share information over the World Wide Web. The Atom Syndication format is built on
Whether you're looking to use plaintext, JSON, or XML in your Ajax calls, WordPress (WP) has you covered. With regards to the latter, the WP_Ajax_Response
RSS (Really Simple Syndication) feeds provide a means for regular visitors of your website to stay informed of your most recent content. You can start a
The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.
Advertiser Disclosure: Some of the products that appear on
this site are from companies from which TechnologyAdvice
receives compensation. This compensation may impact how and
where products appear on this site including, for example,
the order in which they appear. TechnologyAdvice does not
include all companies or all types of products available in
the marketplace.