Hi Everyone, I'd like to know how to duplicate the demo rss feed by just showing one item at a time with a link to the next - anyone have any ideas about that?
Best Wishes
Madeleine
Many thanks David, as usual it works a treat.
Best Wishes
Madeleine
Hi David the code you gave me works a treat; however is there any way of doing it without having to reload the page, the information from the feed is at the bottom of the page and so when the page is reloaded the visitor is taken to the top. Will I need to create a table and then pass it from there? Any help would be greatly appreciated. I have also included the code:
<?php
require("magicparser/MagicParser.php");
// get the current page from the URL
// suppress error reporting
error_reporting(E_ERROR);
$page = $_GET["page"];
// if not set, force to page 1
if (!$page) $page = 1;
function myRecordHandler($item)
{
global $counter;
global $record;
// increment counter
$counter++;
// return false if counter not yet reached page to view
if ($counter < $record) return false;
print "<div class='entry'><strong><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></strong>";
print "<p>".$item["DESCRIPTION"]."</p></div>";
return TRUE;
}
MagicParser_parse("{link saved}","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
if ($counter == $page)
{
print "<div class='more'><p><a href='?page=".($page-1)."'>back</a> ";
print " <a href='?page=".($page+1)."'>Next</a></p></div>";
}
else
{
print "<p>No more articles.";
print " <a href='?page=".($page-1)."'>back</a></p>";
}
?>
Hi Madeline,
You could achieve this using an anchor (A) tag, and appending the tag name to the Next / Back URLs... For example:
<?php
require("magicparser/MagicParser.php");
// get the current page from the URL
// suppress error reporting
error_reporting(E_ERROR);
$page = $_GET["page"];
// if not set, force to page 1
if (!$page) $page = 1;
print "<a name='news' />";
function myRecordHandler($item)
{
global $counter;
global $record;
// increment counter
$counter++;
// return false if counter not yet reached page to view
if ($counter < $record) return false;
print "<div class='entry'><strong><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></strong>";
print "<p>".$item["DESCRIPTION"]."</p></div>";
return TRUE;
}
MagicParser_parse("{link saved}","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
if ($counter == $page)
{
print "<div class='more'><p><a href='?page=".($page-1)."#news'>back</a> ";
print " <a href='?page=".($page+1)."#news'>Next</a></p></div>";
}
else
{
print "<p>No more articles.";
print " <a href='?page=".($page-1)."#news'>back</a></p>";
}
?>
Hope this helps!
Cheers,
David.
Hi David many thanks for that, slight problem though - it doesn't seem to move from record 1, also what is "{link saved}" within the code? This doesn't work as there is no reference to the rss document, the address is: http://wiadomosci.onet.pl/2,kategoria.rss. I'm sure I've done something silly to make it not work. The anchor tag solution is certainly a perfect way of doing it (if I can get it to work!). Any help appreciated.
Best Wishes
Madeleine
Hello Madeleine,
Sorry, I always replace URLs with {link saved}, simply replace that with your URL and then it should work fine!
Cheers,
David.
Hi David I can now get the page; however it doesn't seem to move from the first record, is this because '$record' isn't declared? when I hit next it stays with the same news item and with the 'else' statement of 'no more articles' and displays the 'back' button - any ideas? I would appreciate any thoughts.
Thank you for your time and patience.
Best Wishes
Madeleine
Hi Madeleine,
Yes - it should be $page not $record..
if ($counter < $page) return false;
Sorry about that...
Cheers!
David.
Hi Madeleine,
Sure - here's outline code that will print the title / description of an article from an RSS feed with a link to the next...
<?php
require("MagicParser.php");
// get the current page from the URL
$page = $_GET["page"];
// if not set, force to page 1
if (!$page) $page = 1;
function myRecordHandler($record)
{
global $counter;
global $page;
// increment counter
$counter++;
// return false if counter not yet reached page to view
if ($counter < $page) return false;
print "<h1>".$record["TITLE"]."</h1>";
print "<p>".$record["DESCRIPTION"]."</p>";
return TRUE;
}
MagicParser_parse("http://example.com/rss.xml","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
if ($counter == $page)
{
print "<p><a href='?page=".($page+1)."'>Next</a></p>";
}
else
{
print "<p>No more articles.</p>";
}
?>
Hope this helps!
Cheers,
David.