I need help! Been trying for hours and also by googling and asking other people but don't get this shit to work. I have a php script that displays a feed from my blog. An example can be seen on netmarketing.us I want to set this up on my directories. My directories use the phplinkdirectory script which is done in smarty. If I try this in the template file: {php}include('rss.php');{/php} Nothing gets output as HTML. There is nothing in the source code at all. If I add this to the index.php: include('rss.php'); $tpl->assign('RSS', $RSS); And then use {$RSS} in the template file what happens is that it works but the feed gets displayed on the top of the file before all other HTML code and not where I want it. I really need some help on this and can pay if needed. The only solution I could think of is to use iframes that calls a php file and on that file I can run the script, but iframes are not good SEO wise ... The rss.php looks like this: <?php /* Created by Global Syndication's RSS Parser http://www.globalsyndication.com/rss-parser */ set_time_limit(0); #### Here is the feed URL: $file = "http://www.jimwestergren.com/category/online-marketing/feed/"; $rss_channel = array(); $currently_writing = ""; $main = ""; $item_counter = 0; function startElement($parser, $name, $attrs) { global $rss_channel, $currently_writing, $main; switch($name) { case "RSS": case "RDF:RDF": case "ITEMS": $currently_writing = ""; break; case "CHANNEL": $main = "CHANNEL"; break; case "IMAGE": $main = "IMAGE"; $rss_channel["IMAGE"] = array(); break; case "ITEM": $main = "ITEMS"; break; default: $currently_writing = $name; break; } } function endElement($parser, $name) { global $rss_channel, $currently_writing, $item_counter; $currently_writing = ""; if ($name == "ITEM") { $item_counter++; } } function characterData($parser, $data) { global $rss_channel, $currently_writing, $main, $item_counter; if ($currently_writing != "") { switch($main) { case "CHANNEL": if (isset($rss_channel[$currently_writing])) { $rss_channel[$currently_writing] .= $data; } else { $rss_channel[$currently_writing] = $data; } break; case "IMAGE": if (isset($rss_channel[$main][$currently_writing])) { $rss_channel[$main][$currently_writing] .= $data; } else { $rss_channel[$main][$currently_writing] = $data; } break; case "ITEMS": if (isset($rss_channel[$main][$item_counter][$currently_writing])) { $rss_channel[$main][$item_counter][$currently_writing] .= $data; } else { $rss_channel[$main][$item_counter][$currently_writing] = $data; } break; } } } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); // output HTML ### NOT NEEDED #### print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>"); if (isset($rss_channel["ITEMS"])) { if (count($rss_channel["ITEMS"]) > 0) { # SIFFRAN NUMMER 5 NEDAN ANGER HUR MÃ…NGA SKA VISAS for($i = 0;$i < 5;$i++) { if (isset($rss_channel["ITEMS"][$i]["LINK"])) { print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>"); } else { print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>"); } print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); } } else { print ("<b>There are no articles in this feed.</b>"); } } ?> Code (markup):
Jim, Try using this code: http://forums.digitalpoint.com/showthread.php?t=7354 Also look at this forum for more support http://www.phplinkdirectory.com/forum/viewforum.php?f=8
I am using Zfeeder from http://zvonnews.sourceforge.net/ it's a php script, very easy to setup and allows SSI of own RSS feeds as well as SSI of remote RSS feeds and even to offer your own RSS feeds in WAP format. to the WAP world ... something quiet often used on my site ever since i have it a year ago
Smarty does seem to act up a bit with feeds when you try to display them with an include. I've found 3 ways around this. 1) Check out the Smarty wiki pages, there are a couple of Smarty plugins available for RSS. I don't like these options simply because they place the work of parsing the feed on Smarty, and even though it's able to do it I prefer to utilize Smarty strictly for presentation/display and always use php for scripting functions. 2) If your site is backed by a database, pull the feed into a db table and then extract and assign to Smarty variable for display. I prefer this option. 3) Last resort if your site isn't backed by a db, create a normal php script that grabs and parses the RSS feed you want, have it 'write' the output to a second file called RSSdisplay.html (or whatever you want to call it). Set up a CRON job to run this php script every few hours, or however often you want the feed to update. In your Smarty template file(s) use a Smarty file include statement to include the RSSdisplay.html file. HTH, Scott
Thanks. The script I have is good enough but I will check out this other one. They were not able to help me. And I don't have Newstopia so I don't think that the scripts for that product will help me. Thanks, however it was not what I was looking for. Hi Scott, you seem to know this. My site is using a db yes. I would like help from you as I am a newbie in this. I can pay you a bit for help, like $15. I would be happy if you assisted me.