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;
Edited by QuickOldCar
Link to comment
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.