Insert last posts in a static page using a RSS parser

Before to design a Web project we usually consider several issues to decide whether it is more accurate to perform a static or dynamic Web page. Normally I prefer a dynamic page if the content will be modified by one or more persons, but I recommended a static Web page if the content is light and it will not be changed frequently.

In some cases it might be interesting to create a static page with a dynamic content section such as a news section that can be updated easily.

In this post we will explain how to insert dynamic content in a static page using the RSS parser SimplePie.

SimplePie is a PHP library that allows to parse RSS or Atom feeds and it works perfectly if we have a WordPress blog.

As you can see in this link of this Web application, a specific number of posts are shown with their respective sample images from an RSS feed or blog on a static page.


Using SimplePie class we create an object for each post

$feed = new SimplePie();

Y después con los diferentes métodos que nos ofrece la clase y un par de funciones podremos obtener la imagen y descripción de cada objeto o post así como el enlace a su fuente original.

And then with the different methods offered by the class and a couple of functions we can get the picture and description of each object (post) as well as the link of the original source.

$feedDescription = $item->get_content();
$image = returnImage($feedDescription);
$image = scrapeImage($image);
$image_url= $item->get_permalink();
$description = $item->get_description();

In this link you can download the modified code which can be subsequently reused to insert dynamic content in a static Webs.