Jump to content

my custom blog and rss.


njdubois

Recommended Posts

I'll explain it as simple as can.

 

Make a folder named feed and create an index.php file within or create a new php file anywhere you desire.

 

first line would be header info to declare it's document type

header("Content-Type: application/rss+xml; charset=UTF-8");

connect to your database

perform a select query to database

use LIMIT to return limited amount of results

if there is a result larger than zero continue

 

Adding the rss format code

    $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>';
    $rssfeed .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
    $rssfeed .= '<channel>';
    $rssfeed .= '<atom:link href="http://site.com/feed/" rel="self" type="application/rss+xml"/>';
    $rssfeed .= '<title>Site.com latest feeds</title>';
    $rssfeed .= '<link>http://site.com</link>';
    $rssfeed .= '<description>This is the description of my site</description>';
    $rssfeed .= '<language>en-us</language>';
    $rssfeed .= "<copyright>Copyright (C) 2009-" .date('Y'). " Site.com</copyright>";

Now do a while loop on your results

 

code within the loop

    $rssfeed .= "<item>";
    $rssfeed .= "<title>" . $row['title'] . "</title>";
    $rssfeed .= "<guid>" . $row['permalink'] . "</guid>";
    $rssfeed .= "<description><![CDATA[ <p>". $row['description'] ."</p> ]]></description>";
    $rssfeed .= "<link>" . $row['permalink'] ."</link>";
    $rssfeed .= "<pubDate>" . $row['date'] . "</pubDate>";
    $rssfeed .= "</item>";

end of while loop

 

closing tags and echo out $rssfeed

    $rssfeed .= "</channel>";
    $rssfeed .= "</rss>";
    echo $rssfeed;
  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.