Auto RSS??

Discussion in 'XML & RSS' started by Tropica, Sep 10, 2007.

  1. #1
    Hey

    I was thinking about making an rss feed for my sites news, i can code it up, no problem. What i wanted to know, was there a way the rss feed could auto update its self from my news page, or will I have to do it manually?

    I know im being lazy, but thats what I do best! lol :D

    thanks!
     
    Tropica, Sep 10, 2007 IP
  2. bootzy

    bootzy Peon

    Messages:
    2
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What kind of code/platform is your site running on? You can use PHP & MySQL to automatically update your RSS content.
     
    bootzy, Sep 10, 2007 IP
  3. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #3
    my site is all php, the rss is hand coded in xml

    How would i go about this? Is there a script for it thats free lol ;)
     
    Tropica, Sep 10, 2007 IP
  4. bootzy

    bootzy Peon

    Messages:
    2
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm sure there are good scripts out there, but I'll show you how I did it myself for my own site. I'm assuming that the content for your news articles are already stored in a mysql database, because you'll need that to do this.

    Basically what you do is embed the XML code for your RSS feed within a .php file, and retrieve the most recent "x" number of items from your database.

    My site runs on a modded version of PHP-Nuke, so the code you'll need will probably vary a bit from this, but here's the basic scheme of it:

    
    
    <?php 
    
    include("mainfile.php");
    global $prefix, $db;
    header("Content-Type: text/xml");
    
    
    echo "<?xml version=\"1.0\"?>
    <rss version=\"2.0\">
    <channel>
    
    <title>TITLE OF CHANNEL GOES HERE</title>
    <description>DESCRIPTION OF CHANNEL GOES HERE</description>
    <link>LINK OF SITE GOES HERE</link>";
    
    $result = $db->sql_query("SELECT id, title, subtitle, text2 from ".$prefix."_stories2 ORDER BY id DESC limit 10");
    	while ($myrow = $db->sql_fetchrow($result)) {
    		$id = intval($myrow['id']);
    		$title = $myrow['title'];
    		$subtitle = $myrow['subtitle'];
    		$text2 = $myrow['text2'];
    		$text2 = stripslashes(check_html($text2, "nohtml"));
    		
    		echo "
    		<item>
    		<title>[Featured Artist] $title: $subtitle</title>
    		<description>$text2</description>
    		<link>http://www.website.net/php/story-$id.html</link>
    		</item>";
    			}
    
    echo "
    </channel>
    </rss>";
    
    
    PHP:
    So essentially you code the < channel > like you normally would, and then set up a MySQL query to retrieve however many < item > elements you want displayed in your RSS feed. In this example I have the query set to "DESC limit 10," which means the query will retrieve the 10 most recent articles and display them in the RSS feed in descending order. If you're not familiar with setting up queries, then you'll probably need to take some more time to figure out how to do it properly for your own site and database. I hope this helps, though. I just figured it out for the first time myself a couple days ago and it's been working great for me.
     
    bootzy, Sep 10, 2007 IP
    Tropica likes this.
  5. newsniche

    newsniche Peon

    Messages:
    1,017
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I found the best solution is to use SimplePie. Other than that there are plenty of RSS to Javascript sites that will do the job.
     
    newsniche, Sep 10, 2007 IP
    Tropica likes this.
  6. Tropica

    Tropica Notable Member

    Messages:
    2,431
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    230
    #6
    looks awesome bootzy, thanks :)
     
    Tropica, Sep 10, 2007 IP