Script to display recent articles from any CMS
The easiest way to display a list of recently updated articles The best way to automatically update your feed is to use the site's RSS feed.
The script we wrote, which is based on the functions of the rsslib script of the PHP RSS reader, uses an RSS feed in 2.0 format, which has the advantages of being the simplest and most widespread.
If the site is not built with a CMS that automatically generates tape, you can use the ARA editor, which, starting with version 1.7, sorted articles from the newest to the oldest.
This simplifies the selection of recent articles. Simply load the channel into the array and limit it to the desired number of titles, which is what the RSS_RetrieveLinks function described below does.
Scenario description
The script is designed to get the title, link, description and date of articles. The user must display the required information. You can change the RSS_Recents function if necessary. By default, only headers are displayed.
PHP 5 required.
RSS_Recents
This is a function called for display, and we will see its interface later.
Its role is to call the RSS_RetrieveLinks to retrieve the content of the channel in the table and display it either as a series of links or as an HTML list.
RSS_RetrieveLinks
Its parameters are the URL of the feed and the number of links to return.
It loads the file using the load () DOMDocument method (requires PHP 5) and calls the RSS_Tags function to extract the data.
RSS_Tags
It retrieves information from the channel about the element that is passed as a parameter using the getElementsByTagName method, including the header, reference, and so on.
Use of script
On the page with the list of recent articles, insert the following PHP code:
<?php require_once("recents.php"); echo RSS_Recents("https://www.iqlevsha.ru/rss.xml", 7, false); ?>
Replace the URL with the URL of your site's feed. The second parameter is the number of displayed headings, the third is the ability to place them in <li> tags or not.
In all cases, the list view will depend on the style sheet. Optionally, you can insert <span> into the contents of the $ page variable to assign style rules to specific elements.
Recent Articles Script Demonstration
The script is based on the RSS 2.0 RSS feed, the most simple and widely used.
Demo tape from .fr, and it displays the last seven articles.
- Download Script.
Replace the .txt extension with .php
Optimized script for recent articles
An optimized script has only one function.
Demo tape from .fr; displays the last 7 articles.
- Load a simplified script.
The simplified version stores only the title and URL of articles.