array_slice is smart enough to do the right thing if the $num_items is greater than the actual number of items
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.
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
Some good info. Just wondering if using your PHP code produces a version of the feed that can be spidered by the search engines.
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!
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.
$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.
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.
Quick question: Will this thing add new pages to your site? Or is is just some kind of window showing news from other sites?
Thank you so much, I have been busting my bollocks trying to do this over the last few days, your a star!!!!!!!!!!!!!!
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
<?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.
Great add - I would give you a positive for that add but I seemed to have already given you one - Great Work!
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 =\