Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    Hi Everyone,
    Being a beginner level web designer I don't have a clue about how to add RSS feeds to a website. Can someone explain that? First of all the page the script is on, would have to be .php correct? Then what , do you simply paste some code (and how do you get that code) on the page and it brings you the relevant content?
    Also, how about if you go into a specific news website on your subject, and try to get their RSS feeds to your site. How does this differ form the one above?
    Answers with as much detail as possible is appreciated.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    Your page either needs to have the file extension of .php (instead of .html), or
    the .htaccess file on your website needs to process all .html files as .php.
    Ask your webhost about the .htaccess thing.


    Websites offer RSS feeds.
    An example is here (my local weather conditions for St. Paul) ...
    http://rss.wunderground.com/auto/rss...xml?units=both

    The file they create is called an XML file.

    You then need to use a PHP script that can read that XML file and
    create the text on your web page.

    So, you find a "PHP RSS Reader Script".
    http://www.google.com/search?hl=en&q...+reader+script

    Magpie is the script I'm thinking you might use. I would actually create my
    own XML parser ... but it looks like you don't have the PHP expertise.

    I created my own RSS Reader to "parse" the XML file and use some graphics
    to create my own weather condition on my webpage. Here is my example
    using the Weather Underground RSS Feed:
    http://www.catpin.com/weather

    For those interested in the PHP script, at the very bottom of this post is the
    actual PHP script that I'm using (along with some other graphics I use).

    This is where it can get tricky because your webhost may or may not allow
    some of these to work. Some webhosts have the fopen() function disabled.
    So in some cases, you need to use a thing called "Curl". This is all technical
    and stuff, so here's what you do ...

    The second part of your question is about trying to get their feeds into your site.
    It's related to the first part in that you need PHP scripting to grab the XML file
    and "parse" that file.

    Give us an RSS link that you are interested in.
    Tell us how many entries you will be displaying on your website.

    We'll give you a PHP script to insert into your page to test it out.


    the example PHP script for Weather Underground - St. Paul, Minnesota ...
    PHP Code:
    <?php
     
    echo"
    <style>
    #rss{
    margin: 0px auto;
    font-family: arial;
    font-size: 8pt;
    color: #222;
    width: 150px;
    height: 40px;
    padding: 0px 0px 0px 0px;
    border: 1px solid #555;
    text-align: left;
    }
    </style>
    "
    ;
    $feed_url "http://rss.wunderground.com/auto/rss_full/MN/Saint_Paul.xml?units=both"

    # INITIATE CURL.
    $curl curl_init();

    # CURL SETTINGS.
    curl_setopt($curlCURLOPT_URL,"$feed_url");
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0);

    # GRAB THE XML FILE.
    $xmlTwitter curl_exec($curl);

    curl_close($curl);

    # SET UP XML OBJECT.
    $xml = new SimpleXMLElement($xmlTwitter);

    foreach (
    $xml->channel as $channel ){                    
    $line=$channel->item->title;
    }

    $city="St. Paul, MN"
    echo 
    "<div id='rss'>\n"
    list (
    $temp$conditions) = split ('\|'$line);
    list (
    $far$cel) = split ('\/'$temp);
    list (
    $one$two$three$four) = split (' '$far);
    list (
    $left,$right) = split ('-',$conditions);
    $con="pixel.gif";
    if(
    strstr($conditions'vercast')){$con="overcast.gif";}
    if(
    strstr($conditions'ain')){$con="rain.gif";}
    if(
    strstr($conditions'og')){$con="fog.gif";}
    if(
    strstr($conditions'aze')){$con="haze.gif";}
    if(
    strstr($conditions'now')){$con="snow.gif";}
    if(
    strstr($conditions'loudy')){$con="cloudy.gif";}
    if(
    strstr($conditions'unny')){$con="sunny.gif";}
    if(
    strstr($conditions'lear')){$con="sunny.gif";}
    if((
    strstr($conditions'unny'))&&(strstr($conditions'artly'))){$con="partly.sunny.gif";}
    if((
    strstr($conditions'loudy'))&&(strstr($conditions'artly'))){$con="partly.cloudy.gif";}
    if((
    strstr($conditions'loudy'))&&(strstr($conditions'ostly'))){$con="mostly.cloudy.gif";}
    if((
    strstr($conditions'louds'))&&(strstr($conditions'catter'))){$con="partly.cloudy.gif";}
    echo 
    "
    <img src='
    $con' width='50' height='40' alt='$con' title='$con' border='0' style='float: left; padding: 0px 5px 0px 0px;' />
    <b>
    $city</b><br>$four<br>$left
    "
    ;

    echo 
    "</div>\n"
    ?>


  4. #3
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    http://robots.net/syndicate.html
    is one place that I am trying to get the RSS from...5 entries would be ok..
    One general question: Is it ok to publish RSS from any website on your website or you need to get permission first each time? The link I wrote above, they are saying that it is ok to get their RSS to our website, but many sites with RSS feeds don't say anything about it.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    The whole point of RSS is to allow people to use your information.
    By providing an RSS feed, you control what they use, and also control
    the caching of the information, so people can access it without hot-linking
    to the actual website (the RSS XML file is cached).

    In return, the RSS feed provides links back to your site, which draws back
    people interested in seeing more, or related information.

    It ends up being a give-and-take relationship.

    ================

    Here is my working example for your RSS Feed:
    http://www.catpin.com/robots_net.php

    I deliberately left the paragraph unformatted so if you were to insert into
    a <div> section, it would be controlled by your own CSS style sheet.

    Also note there are a couple of things you can affect ... how many items,
    and how many characters to show for each item (example: ... read more)

    You can copy the code below and save-as "robots.php". Upload to your website
    and test it out all by itself to see if it works. I mention that because not all
    webhosts allow PHP Curl Functions. I just think Curl is the easy way to do it.

    If you save the code below as "robots.php", you can insert the RSS Feeds into
    any .php page by putting this where you want it to appear:
    <?php include("robots.php");?>


    Here's the PHP script:
    PHP Code:
    <?php 
    // rss page for Robots.net - 
    $feed_url "http://robots.net/rss/articles.xml"

    # INITIATE CURL.
    $curl curl_init();

    # CURL SETTINGS.
    curl_setopt($curlCURLOPT_URL,"$feed_url");
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0);

    # GRAB THE XML FILE.
    $xmlTwitter curl_exec($curl);

    curl_close($curl);

    # SET UP XML OBJECT.
    $xml = new SimpleXMLElement($xmlTwitter);

    // How many items to display
    $count 5;

    // How many characters from each item
    // 0 (zero) will show them all.
    $char 200;

    foreach (
    $xml->channel->item as $item) {
    if(
    $char == 0){
    $newstring $item->description;
    }
    else{
    $newstring substr($item->description0$char);
    }
    if(
    $count 0){
    //in case they have non-closed italics or bold, etc ...
    echo"</i></b></u></a>\n";
    echo
    "
    <div style='font-family:arial; font-size:.8em;'> 
    <b>
    {$item->title}</b><br /> 
    $newstring ... <a href='{$item->guid}'>read more</a>
    <br /><br />
    </div>
    "

    }
    $count--;

    ?>


  6. #5
    Senior Member ravensjeff's Avatar
    Join Date
    Aug 2007
    Location
    Maryland
    Posts
    125
    Member #
    15751
    First off, fantastic stuff. Thanks for taking the time to post this.

    Wanting to play around with it, I uploaded your code and a test page to my webserver. I get the following error:

    Fatal error: Cannot instantiate non-existent class: simplexmlelement

    Any thought?

  7. #6
    Senior Member ravensjeff's Avatar
    Join Date
    Aug 2007
    Location
    Maryland
    Posts
    125
    Member #
    15751
    I found the problem...my webserver was set to run PHP 4. Silly me.

  8. #7
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    I tried your code. Loaded it as a seperate php page. Then made a link to it from my index.html to that php page. When I clicked, first it gave the same error like ravensjeff's. Then I also upgraded to php 5. This time it took a long time for page to load, and then nothing appeared/happened. Just plain white page. Tried a few times and it's the same. Any ideas?
    By the way one general question here: As I said my index page is html. SO I did a seperate page for the php code you gave me. I can not run a php script inside an html page right?

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    To run a PHP script inside a .html file, you need to either set that
    with your webhost (to process .html files as PHP), or set it in .htaccess
    Google: .htaccess HTML as PHP

    About the other thing ...

    $xml = new SimpleXMLElement($xmlTwitter);


    I'm having ISP issues tonight, so I'll just post what I think you can try:

    # SET UP XML OBJECT.
    //$xml = new SimpleXMLElement($xmlTwitter);
    $xml = simplexml_load_string($xmlTwitter);

    comment-out the simplexmlelement line
    and add the simplexml_load_string line.

    See what happens.

    I think this is a PHP config/revision issue.


  10. #9
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    Here's my test page with the alternate XML OBJECT.
    See if this works better for you on your server.

    http://www.catpin.com/robots2_net.php

    Here's the PHP script:
    PHP Code:
    <?php  
    // rss page for Robots.net -  
    $feed_url "http://robots.net/rss/articles.xml";  

    # INITIATE CURL. 
    $curl curl_init(); 

    # CURL SETTINGS. 
    curl_setopt($curlCURLOPT_URL,"$feed_url"); 
    curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT0); 

    # GRAB THE XML FILE. 
    $xmlTwitter curl_exec($curl); 

    curl_close($curl); 

    # SET UP XML OBJECT. 
    //$xml = new SimpleXMLElement($xmlTwitter);
    $xml simplexml_load_string($xmlTwitter); 

    // How many items to display 
    $count 5

    // How many characters from each item 
    // 0 (zero) will show them all. 
    $char 200

    foreach (
    $xml->channel->item as $item) { 
    if(
    $char == 0){ 
    $newstring $item->description

    else{ 
    $newstring substr($item->description0$char); 

    if(
    $count 0){ 
    //in case they have non-closed italics or bold, etc ... 
    echo"</i></b></u></a>\n"
    echo

    <div style='font-family:arial; font-size:.8em;'>  
    <b>
    {$item->title}</b><br />  
    $newstring ... <a href='{$item->guid}'>read more</a> 
    <br /><br /> 
    </div> 
    "
    ;  

    $count--; 
    }  
    ?>


  11. #10
    Senior Member ravensjeff's Avatar
    Join Date
    Aug 2007
    Location
    Maryland
    Posts
    125
    Member #
    15751
    One more quick question...can you tell me if it is possible to add target="_blank" to the line:

    PHP Code:
    $newstring ... <a href='{$item->guid}'>read more</a


    I tried to concatenate after $item->guid} but that did work or I didn't do it correctly.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:54 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com