Using an RSS feed in left sidebar

Can't get it installed? Not sure how a feature works? Then post here.

Using an RSS feed in left sidebar

Postby patriotslist » 2012-09-03 10:16 am

Hello,

I figured I'd give this a shot. I am trying to display an rss feed in a left column of my top site. The code I've found works great in a number of sites I have. It is located here if your looking for a great solution: http://forums.digitalpoint.com/showthread.php?t=7354

It will not however work in aardvark for some reason.

Here is the issue I encounter when using this code.

Code: Select all
%s", trim($link),htmlspecialchars(trim($title))); printf("
%s ",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 "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("http://www.patriotslist.com/feed.php","r") or die("Error reading RSS data."); while ($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))); fclose($fp); xml_parser_free($xml_parser); ?>
patriotslist
Advanced Member
 
Posts: 31
Joined: 2009-05-18 11:44 am

Re: Using an RSS feed in left sidebar

Postby Jeremy » 2012-09-15 08:24 pm

You can't embed PHP directly in the template. You'll have to put that in some other .php file and then have an include point at that.
Jeremy
Supreme Diety
 
Posts: 8922
Joined: 2003-05-05 04:41 pm
Location: NJ, USA

Re: Using an RSS feed in left sidebar

Postby patriotslist » 2012-09-16 11:06 am

Thanks Jeremy,

I've created a new .php file and included the rss code I know works elsewhere. I've uploaded the new file to the main directory. The file includes this code.

Code: Select all
<?php
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
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'>%s</a></b></dt>",
  trim($link),htmlspecialchars(trim($title)));
  printf("<dt>%s</dt>&nbsp;",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 "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("http://www.patriotslist.com/feed.php","r")
 or die("Error reading RSS data.");
while ($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)));
fclose($fp);
xml_parser_free($xml_parser);
?>


I've added the include code to the wrapper in a float left div:
Code: Select all
<?php include("myrss.php"); ?>


I now do not receive the error but the rss does not display in the div.
patriotslist
Advanced Member
 
Posts: 31
Joined: 2009-05-18 11:44 am

Re: Using an RSS feed in left sidebar

Postby tysonlee » 2012-10-15 06:42 am

I need to customize my topsite a little bit. Mainly I want to add one more field. How can I do that the easiest way? I started out but stopped since it got quite confusing and it seems to be a lot of files to edit in order for this to work out nice. I have seen topics where people respond that it's just to duplicate an other field but what files do I need to duplicate?
tysonlee
Newbie
 
Posts: 1
Joined: 2012-10-15 06:41 am


Return to Support

Who is online

Users browsing this forum: No registered users and 5 guests

cron