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,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 359
  • Total: 359

Tip: How to limit the number of RSS titles displayed

Started by wayco, September 19, 2008, 03:20:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wayco

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.

Ken.

Thanks for the tip wayco and welcome to TinyPortal.

I've not tried this myself, but fresh code is always welcome here on TP.  :)
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

wayco

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.

adamcanada

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

IchBin


adamcanada

Yes, I ended up having to go through Feedburner to get these limited

IchBin

IMO, its much better to use a 3rd party software do that anyway. :) Glad you got what you want.

wayco

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>';

This website is proudly hosted on Crocweb Cloud Website Hosting.