TinyPortal

Development => Support => Topic started by: wayco on September 19, 2008, 03:20:48 AM

Title: Tip: How to limit the number of RSS titles displayed
Post by: wayco on September 19, 2008, 03:20:48 AM
Hello everyone and I hope I'm putting this in the right place, or that it will end up there. The following is my hack of TP to limit the number of titles/teasers in an RSS feed. My setup:

Link to my site: n/a at the moment
SMF version: 1.15
TP version: 1.05b
Theme name and version: not theme dependant
Mods installed: advshout
Related Error messages: none

After reading 2-3 years of questions about limiting the number of RSS titles in the TP software itself but finding no answers that didn't require add-ons, I did a little poking and prodding and this is what I came up with. It's not elegant, but it seems to work.

In the file  Sources/TPmodules.php, make the following changes:


FIND
global $context, $insideitem, $tag, $title, $description, $link, $tpimage, $curl;

if ($tagName == "ITEM")
{

CHANGE TO
global $context, $insideitem, $tag, $title, $description, $link, $tpimage, $curl, $rss_counter;

if ($tagName == "ITEM")
{
$rss_count ++;
if($rss_count < 11) { //change this number to desired titles plus 1



FIND
printf("<img src='%s' alt='' style='margin: 0;' />", trim($tpimage));
echo '</div>';

ADD AFTER
}
else



FIND
function TPparseRSS($override = '')
{

global $context, $settings, $options, $scripturl, $txt, $modSettings;

CHANGE TO
function TPparseRSS($override = '')
{

global $context, $settings, $options, $scripturl, $txt, $modSettings, $rss_count;



FIND
// Close the datafile
fclose($fp);

ADD AFTER
$rss_count = 0;


I will attempt to refine this to add an article limit box at the top of each feed that can be set by the user. Comments and/or suggestions are welcome.
Title: Re: Tip: How to limit the number of RSS titles displayed
Post by: Ken. on September 26, 2008, 10:11:01 AM
Thanks for the tip wayco and welcome to TinyPortal.

I've not tried this myself, but fresh code is always welcome here on TP.  :)
Title: Re: Tip: How to limit the number of RSS titles displayed
Post by: wayco on September 28, 2008, 08:48:35 PM
Hi Ken. Love the TP concept but am at odds with some of the code, so expect lots more as I become more familiar with it. Thanks for the cordial welcome.

If anyone has tried this, please let me know how it works for you.
Title: Re: Tip: How to limit the number of RSS titles displayed
Post by: adamcanada on October 15, 2008, 06:32:52 AM
I followed this tutorial and made the changes but it didn't seem to change the number of titles that were displayed, it stayed the same unfortunately
Title: Re: Tip: How to limit the number of RSS titles displayed
Post by: IchBin on October 15, 2008, 03:28:57 PM
Did you change the number to your desired count?
Title: Re: Tip: How to limit the number of RSS titles displayed
Post by: adamcanada on October 15, 2008, 04:02:12 PM
Yes, I ended up having to go through Feedburner to get these limited
Title: Re: Tip: How to limit the number of RSS titles displayed
Post by: IchBin on October 15, 2008, 06:24:44 PM
IMO, its much better to use a 3rd party software do that anyway. :) Glad you got what you want.
Title: Re: Tip: How to limit the number of RSS titles displayed
Post by: wayco on October 16, 2008, 04:04:45 AM
I'm not sure how the changes I originally posted could fail to limit the titles, but in any event here's a much improved version that makes use of the upshrink routine to hide additional feed titles until clicked. Other than that, the changes are to the same section of code that as far as I can tell is responsible for displaying the RSS feeds.

IN /Sources/TPmodules.php
FIND

global $context, $insideitem, $tag, $title, $description, $link, $tpimage, $curl;

if ($tagName == "ITEM")
{


CHANGE TO

global $context, $insideitem, $tag, $title, $description, $link, $tpimage, $curl, $rss_count;

if($rss_count==3) {
    $uid=strrchr($context['TPortal']['rss'],'/');
    echo '<a href="javascript: void(0); return false" onclick="toggle(\''.$uid.'\'); return false" id="blockcollapse'.$uid.'" />more...</a><div id="block'.$uid.'" style="display:none;">';
    $rss_count++;
}
else {
if ($tagName == "ITEM")
{
        $rss_count++;


FIND

$title = $description = $link = $insideitem = $curl = false;
}
}


ADD AFTER

}


FIND

function TPparseRSS($override = '')
{

global $context, $settings, $options, $scripturl, $txt, $modSettings;


CHANGE TO

function TPparseRSS($override = '')
{

global $context, $settings, $options, $scripturl, $txt, $modSettings, $rss_count;


FIND

// Close the datafile
fclose($fp);


ADD AFTER

$rss_count=0;
echo '</div>';