1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Using an RSS Feed (This is Easy)

Discussion in 'XML & RSS' started by yfs1, Jan 5, 2005.

  1. Trance-formation

    Trance-formation Peon

    Messages:
    598
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #41
    array_slice is smart enough to do the right thing if the $num_items is greater than the actual number of items:)
     
    Trance-formation, Jan 15, 2005 IP
  2. dirtdog1960theone

    dirtdog1960theone Active Member

    Messages:
    124
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #42
    Reading older posts I think I am going to give this a try. I use rss feeds on my My Yahoo and like them. I am going to see if I can make them work on one of my sites. [​IMG]
     
    dirtdog1960theone, Feb 14, 2005 IP
  3. wendydettmer

    wendydettmer Peon

    Messages:
    1,462
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    0
    #43
    The lil php thing kicks BUTT, i LOVE it.

    I just wish i knew ANYTHING about php, because I woudlnt' mind editing it to only show a certain number of results. But it's a neat lil thing :)
     
    wendydettmer, Feb 14, 2005 IP
  4. CanadianEh

    CanadianEh Notable Member

    Messages:
    3,812
    Likes Received:
    380
    Best Answers:
    0
    Trophy Points:
    260
    #44
    Some good info. Just wondering if using your PHP code produces a version of the feed that can be spidered by the search engines.
     
    CanadianEh, Feb 15, 2005 IP
  5. yfs1

    yfs1 User Title Not Found

    Messages:
    13,798
    Likes Received:
    922
    Best Answers:
    0
    Trophy Points:
    0
    #45
    Absolutely, I actually bring in vistors on one of my sites where I rank for keyword phrases (sometimes strange) that are a combination of static content and the content of the feed that particular day

    Good Luck and post back if the code was helpful!
     
    yfs1, Feb 15, 2005 IP
    wendydettmer and Design Agent like this.
  6. CanadianEh

    CanadianEh Notable Member

    Messages:
    3,812
    Likes Received:
    380
    Best Answers:
    0
    Trophy Points:
    260
    #46
    Awesome. I had gotten a bunch of feeds working but the static content can be a big plus. Thanks for the quick and helpful response.
     
    CanadianEh, Feb 15, 2005 IP
  7. saintdw

    saintdw Peon

    Messages:
    453
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #47
    $int = 0;
    while ($int != 3){
    $data = fread($fp, 4096);
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));

    $int++;
    }
    fclose($fp);

    xml_parser_free($xml_parser);

    This line of code. In while loop if you change i != 1 it will show 4 things, i!=2 it will show 8 things, etc, etc.

    I dont know yet how to break it up into less. When i have time ill try to pull the data and instead of parsing it, slap it into array and then print the number of items needed.
     
    saintdw, Feb 24, 2005 IP
    wendydettmer likes this.
  8. CanadianEh

    CanadianEh Notable Member

    Messages:
    3,812
    Likes Received:
    380
    Best Answers:
    0
    Trophy Points:
    260
    #48
    yfs1

    Very nice script. Thank you for sharing it.
     
    CanadianEh, Feb 24, 2005 IP
  9. sifuhall

    sifuhall Active Member

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #49
    I think this is fantastic and I thank you very much for sharing this.

    However, I must point out for those of you that place importance on having your pages validate that this is not valid html.

    It appears the opening and closing dl tags are missing.

    Please correct me if I am wrong on that, and thanks again for posting this.
     
    sifuhall, Feb 24, 2005 IP
  10. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #50
    Quick question:
    Will this thing add new pages to your site? Or is is just some kind of window showing news from other sites?
     
    fryman, Feb 24, 2005 IP
  11. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #51
    Thank you so much, I have been busting my bollocks trying to do this over the last few days, your a star!!!!!!!!!!!!!!
     
    Jim bob 9 pants, Feb 24, 2005 IP
  12. sifuhall

    sifuhall Active Member

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #52

    it adds content to existing pages
     
    sifuhall, Feb 24, 2005 IP
  13. yfs1

    yfs1 User Title Not Found

    Messages:
    13,798
    Likes Received:
    922
    Best Answers:
    0
    Trophy Points:
    0
    #53
    You can also create your own RSS Feeds, put them on your other sites and instantly have fresh content by only changing one feed.

    You can further take advantage by using this technique with the rotating code so if you implore it sitewide, Google will always see changing content.

    Also keep in mind you can control where the links go so if you have one site you really want to promote that month, you can do it with 5 minutes work.

    Cheers and I am glad to hear so many have found this useful. Thanks to those who have added to it. If someone changes to code to limit the amount displayed to 5, please post it in its entirety (Don't post: change this to this...Its much more useful to have all the code so you can just cut and paste)

    Cheers
     
    yfs1, Feb 25, 2005 IP
  14. Thewormman

    Thewormman Peon

    Messages:
    95
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #54
    Could you show this mod as the whole code so I can see exactly how it is modified?

    Thanks
     
    Thewormman, Feb 27, 2005 IP
  15. saintdw

    saintdw Peon

    Messages:
    453
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #55
    <?php
    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    $locations = array('http://michaelthompson.org/news/goo-world.xml', 'http://forums.seochat.com/external.php', 'http://michaelthompson.org/news/goo-world.xml');
    srand((float) microtime() * 10000000); // seed the random gen 
    $random_key = array_rand($locations);
    function startElement($parser, $name, $attrs) {
     global $insideitem, $tag, $title, $description, $link;
     if ($insideitem) {
      $tag = $name;
     } elseif ($name == "ITEM") {
      $insideitem = true;
     }
    }
    function endElement($parser, $name) {
     global $insideitem, $tag, $title, $description, $link;
     if ($name == "ITEM") {
      printf("<dt><b><a href='%s' target=new>%s</a></b></dt>",
      trim($link),htmlspecialchars(trim($title)));
      printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));
      $title = "";
      $description = "";
      $link = "";
      $insideitem = false;
     }
    }
    function characterData($parser, $data) {
     global $insideitem, $tag, $title, $description, $link;
     if ($insideitem) {
     switch ($tag) {
      case "TITLE":
      $title .= $data;
      break;
      case "DESCRIPTION":
      $description .= $data;
      break;
      case "LINK":
      $link .= $data;
      break;
     }
     }
    }
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen($locations[$random_key], 'r')
     or die("Error reading RSS data.");
    $int = 0;
    while ($int != [b]n[/b]){
    $data = fread($fp, 4096);
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    
    $int++;
    }
    fclose($fp);
    
    xml_parser_free($xml_parser);
    
    ?>
    Code (markup):
    n in while loop number to be changed. At n=3+ It will display all things, n =1 will display 1-4 things ( depends on feed), 2 will display 5-9 things.
     
    saintdw, Feb 27, 2005 IP
    miko67, Thewormman and ResaleBroker like this.
  16. Vikkeedee

    Vikkeedee Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #56
    Thanks for the info ...
     
    Vikkeedee, Feb 27, 2005 IP
  17. Thewormman

    Thewormman Peon

    Messages:
    95
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #57
    EXCELLENT Saintdw

    Thanks very much!!!!!!!!!!!!! :D
     
    Thewormman, Feb 28, 2005 IP
  18. yfs1

    yfs1 User Title Not Found

    Messages:
    13,798
    Likes Received:
    922
    Best Answers:
    0
    Trophy Points:
    0
    #58
    Great add - I would give you a positive for that add but I seemed to have already given you one - Great Work!
     
    yfs1, Feb 28, 2005 IP
    Thewormman and albemarle24 like this.
  19. saintdw

    saintdw Peon

    Messages:
    453
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #59
    My pleasure :)

    Was pretty simple, i want to do it so i can control the number of items displayed completely but i dont have time to look into that right now =\
     
    saintdw, Feb 28, 2005 IP
  20. Diamondbacks

    Diamondbacks Peon

    Messages:
    107
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #60
    If I only wanted to display one feed location what would I need to change to make it work? :confused:
     
    Diamondbacks, Feb 28, 2005 IP