Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Limit ITEMS parsed in RSS
Old 05-17-2009, 10:02 PM Limit ITEMS parsed in RSS
Junior Talker

Posts: 1
Trades: 0
Hello everyone,

Just registered an account with webmaster-talk after spending hours searching for a solution to my problem.

I downloaded Smarty and MagpieRSS used to make running RSS Feeds really easy. It works fine if I want all the news scripts to show up, it also works fine if I want one.

I want to have 1-3 news feeds on front page. 8-10 on individual page.

Doing some research on my own, for hours. I discovered a few 'solutions' to limit the amount of items parsed by magpierss. I just can't seem to get it to work, here is what I was told to do:

Code:
You want to display the 10 (or 3) most recent headlines, but the RSS feed
contains 15.

SOLUTION:

$num_items = 10;
$rss = fetch_rss($url);

$items = array_slice($rss->items, 0, $num_items);
Here is my code:

Code:
<?
$mydir = "/rss";

require_once($_SERVER["DOCUMENT_ROOT"].$mydir."/Smarty/libs/Smarty.class.php");
require_once($_SERVER["DOCUMENT_ROOT"].$mydir."/magpierss/rss_fetch.inc");

$tpl = new Smarty();

$tpl->template_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/templates/';
$tpl->compile_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/templates_c/';
$tpl->config_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/configs/';
$tpl->cache_dir = $_SERVER["DOCUMENT_ROOT"].$mydir.'/cache/';

$url = "http://www.abc.net.au/news/indexes/westernvic/rss.xml";

$num_items = 10;
$rss = fetch_rss($url);

$items = array_slice($rss->items, 0, $num_items);

// echo "<pre>"; print_r($rss); echo "</pre>";

if ($rss) { 

define('magpie_cache_age', 1800); # 30 x 60 = 1800 seconds

$tpl->assign("feedtitle",$rss->channel["title"]);

$tpl->assign("items",$rss->items);
}
else {

$tpl->assign("feedtitle","Problem with: $url");
}



$feedhtml = $tpl->fetch($_SERVER["DOCUMENT_ROOT"].$mydir."/templates/newslist.html");

echo $feedhtml;
?>
Thanks in advance if we are able to find a solution.

- Solipsist

Last edited by solipsist; 05-17-2009 at 10:04 PM.. Reason: Thanks in advance!
solipsist is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-17-2009, 10:25 PM Re: Limit ITEMS parsed in RSS
Defies a Status

Posts: 1,605
Trades: 0
I only played with magpie for a while before I used another script. The actual limit on the items is controlled in the // RSS to HTML webpage script v.1.2 on line 37.

You can modify or adapt that code to your purpose:

Quote:
// RSS to HTML webpage script v.1.2
//
// Copyright 2002-2006 ExtraLabs Software
//
// Website: http://www.extralabs.net
// Support: support@extralabs.net
//
// License: Freeware
// This script may be used freely for business or personal use
Line 37 in the script:
// the next line controls the maximum number of items retrieved
$FeedMaxItems = 5;
if (isset($_REQUEST["MAXITEMS"])) {
$FeedMaxItems = $_REQUEST["MAXITEMS"];
}
Note it still fetchs them all but you limit what is displayed.
__________________
Colbyt

Please login or register to view this content. Registration is FREE

Last edited by colbyt; 05-17-2009 at 10:26 PM..
colbyt is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Limit ITEMS parsed in RSS
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10681 seconds with 12 queries