TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,993
  • Total Topics: 21,324
  • Online today: 388
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 283
  • Total: 283

Help with RSS insertion

Started by Skyview, February 28, 2007, 10:25:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Skyview

I know this is probably a dumb nub question but here goes anyway. I want to setup a few rss feeds for display on my site. However, I either need help figuring out hot to put them in an article OR someone tell me how to setup a block with rss type that doesn't get displayed on every part of the site (i.e. I don't want it on the common left, right, or center but on their own pages 1 feed per page lets say).

I setup rss feeds as a test in the block manager and they work great, but I want them in their own little area, not displayed in the common panels. Ideally, I would have menu items in the site map that say News 1, News 2, News 3 as examples, and when I click on News 1, it brings up the feed from a particular source. Same for any others. I'm sure there's probably an easy way to do this but I'm just not seeing it yet.

Lesmond

use this in a PHP article and link to that article in your menu
Place the feed inside the quotes "place your rss feed here inside the quotes"

// An RSS Reader to grab news from whichever site you choose
$backend = "place your rss feed here inside the quotes"; //change this to match the rss feed url you wish to display.
// end


function endtheElement($parser, $tagName) {
// This function is used when an end-tag is encountered.
global $insideitem, $tag, $title, $description, $link;
 
  if ($tagName == "ITEM") {
    echo '<table width="100%" border="0"><tr>
      <td class="main-table">
      <span class="nav-head"><strong>
      ';
    printf("<p><b><a href='%s'>%s</a></b></p>", // make our title into an actual link
    trim($link),htmlspecialchars(trim($title))); // remove html characters from the title
 
    echo "</tr>";
    echo '<tr>
      <td class="nav">';
    printf("<p>%s</p>",$description); // Print out the live journal entry
    echo"</td>";
    echo "</tr>";
    echo "</table>";
    echo "<br>";
    $title = $description = $link = $insideitem = false;
   }
}

// Now to the parsing itself. Starts by creating it:

$xml_parser = xml_parser_create();

// Then setup the handlers:

xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");

// Open the actual datafile:

$fp = fopen($backend, r);

// Run through it line by line and parse:

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)));
}

// Close the datafile

fclose($fp);

// Free any memmory used

xml_parser_free($xml_parser);

Skyview

Hey thanks! That works nicely  :up: Just a note to the developers though. From a users perspective it would be really nice to have the same RSS Feed option that is in the block manager when creating articles. BTW, is there actually anyway to define blocks that are only used on certain custom pages and not all the time?

h0ng0s

Anyway to limit the lines pulled to say 10 articles or character limit?

Lesmond

have a look in the block code snippets board http://www.tinyportal.net/index.php?board=46.0 you may find something there

vanguard


This website is proudly hosted on Crocweb Cloud Website Hosting.