Advertisement:

Author Topic: Code for adding RSS to every forum and subforum  (Read 30563 times)

Offline torkil

  • Jr. Member
  • **
  • Posts: 126
  • Gender: Male
Code for adding RSS to every forum and subforum
« on: June 03, 2005, 03:57:11 AM »
I have made modifications to my theme so that the template is always showing an RSS link for the forum you are currently in. I run a martial arts forum, so if a user wants an RSS to the whole forum he can get that from the frontpage, if he wants an RSS for one of the subforums he can get that from the subforums page.

See it in action at http://www.kampforum.com/forum/ (look for the orange RSS-button!)

The RSS-feeds are both added as a link-tag in the page header and as a regular html-tag in the breadcrumb area.

Here is my code that i place in index.template.php, right before the stylesheet is added, inside the head-area:
Code: [Select]
// Print RSS if it is turned on
if (!empty($modSettings['xmlnews_enable'])) {
if ($_REQUEST['board']) {
$spotnumber = count($context['linktree'])-1;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '
<link rel="alternate" type="application/xml" title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" /> ';
} elseif ($_REQUEST['topic']) {
$spotnumber = count($context['linktree'])-2;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '
<link rel="alternate" type="application/xml" title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" /> ';
} else {
echo '
<link rel="alternate" type="application/xml" title="Kampforum RSS: 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;limit=20" /> ';
}
}

This is the code I use for adding the RSS-link at the end of the breadcrumbs. Put this code at the end of function theme_linktree() inside index.template.php:
Code: [Select]
// Print RSS link if it is turned onon
if (!empty($modSettings['xmlnews_enable'])) {
echo '<div style="float: left; background-color: #f90; font-size: 9px; border: 1px solid #fc0; padding: 0px 2px;; line-height: 1em;">';
if ($_REQUEST['board']) {
$spotnumber = count($context['linktree'])-1;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
} elseif ($_REQUEST['topic']) {
$spotnumber = count($context['linktree'])-2;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
} else {
echo '<a title="Kampforum RSS: 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
}
echo 'RSS</a>';
echo '</div>';
}

Currently the forums title isn't being put in there correctly, but I'm asking around on the general questions forum in this thread to get help to fix that.
« Last Edit: June 03, 2005, 04:02:25 AM by torkil »

Offline torkil

  • Jr. Member
  • **
  • Posts: 126
  • Gender: Male
Re: Code for adding RSS to every forum and subforum
« Reply #1 on: June 03, 2005, 07:34:28 AM »
Allright, with [Unknown]s help I figured out how to get board titles in the RSS-feed title:

in Sources/News.php, change the following:
Code: [Select]
// Show an xml file representing recent information or a profile.
function ShowXmlFeed()
{
global $context, $scripturl, $txt, $modSettings;

with the following:
Code: [Select]
// Show an xml file representing recent information or a profile.
function ShowXmlFeed()
{
global $context, $scripturl, $txt, $modSettings, $db_prefix, $board;

Then, at around line 113, change this:
Code: [Select]
if ($xml_format != 'smf')
{

To this:

Code: [Select]
if ($xml_format != 'smf')
{
// Fetch name of the current board
if ($board == 0) {
$boardname = 'All forums';
} else {
$request = db_query("
SELECT b.name
FROM {$db_prefix}boards AS b
WHERE b.ID_BOARD = $board
LIMIT 1", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request)) {
$boardname = $row['name'];
}
}

And finally: change this line
Code: [Select]
<title>', strip_tags($context['forum_name']), '</title>
To this:
Code: [Select]
<title>', strip_tags($context['forum_name']), ' feed - '.$boardname.'</title>

Now lets just cross our fingers and hope that this functionality is in place in version 1.0.4 or 1.1 or what ever comes next :D

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,604
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Re: Code for adding RSS to every forum and subforum
« Reply #2 on: June 25, 2005, 09:03:08 AM »
The code displays nothing in my case (SMF 1.0) although I have enabled RSS and I can get it with a direct link.

http://www.translatum.gr/forum/index.php

I ended up adding manually the RSS link
Code: [Select]

<table width="100%" cellpadding="3" cellspacing="0">
<tr>
<td valign="bottom"><span class="nav" style="font-size: smaller; margin-right: 5px; display: block; float: left;"><b><a href="http://www.translatum.gr/forum/index.php" class="nav">Translatum Forum</a></b></span><div style="float: left; background-color: #f90; font-size: 9px; border: 1px solid #fc0; padding: 0px 2px;; line-height: 1em;"><a title="Translatum.gr RSS: 30 latest" href="http://www.translatum.gr/forum/index.php?action=.xml;type=rss;sa=recent;limit=30" style="font-weight: normal; text-decoration: none; color: #fff;">RSS</a></div></td>

<td align="right">
</td>
</tr>
</table>

I have made modifications to my theme so that the template is always showing an RSS link for the forum you are currently in. I run a martial arts forum, so if a user wants an RSS to the whole forum he can get that from the frontpage, if he wants an RSS for one of the subforums he can get that from the subforums page.

See it in action at http://www.kampforum.com/forum/ (look for the orange RSS-button!)

The RSS-feeds are both added as a link-tag in the page header and as a regular html-tag in the breadcrumb area.

Here is my code that i place in index.template.php, right before the stylesheet is added, inside the head-area:
Code: [Select]
// Print RSS if it is turned on
if (!empty($modSettings['xmlnews_enable'])) {
if ($_REQUEST['board']) {
$spotnumber = count($context['linktree'])-1;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '
<link rel="alternate" type="application/xml" title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" /> ';
} elseif ($_REQUEST['topic']) {
$spotnumber = count($context['linktree'])-2;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '
<link rel="alternate" type="application/xml" title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" /> ';
} else {
echo '
<link rel="alternate" type="application/xml" title="Kampforum RSS: 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;limit=20" /> ';
}
}

This is the code I use for adding the RSS-link at the end of the breadcrumbs. Put this code at the end of function theme_linktree() inside index.template.php:
Code: [Select]
// Print RSS link if it is turned onon
if (!empty($modSettings['xmlnews_enable'])) {
echo '<div style="float: left; background-color: #f90; font-size: 9px; border: 1px solid #fc0; padding: 0px 2px;; line-height: 1em;">';
if ($_REQUEST['board']) {
$spotnumber = count($context['linktree'])-1;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
} elseif ($_REQUEST['topic']) {
$spotnumber = count($context['linktree'])-2;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
} else {
echo '<a title="Kampforum RSS: 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
}
echo 'RSS</a>';
echo '</div>';
}

Currently the forums title isn't being put in there correctly, but I'm asking around on the general questions forum in this thread to get help to fix that.
« Last Edit: June 25, 2005, 11:24:57 AM by spiros »

Offline carlatf

  • Jr. Member
  • **
  • Posts: 213
  • Gender: Female
    • Buscador de Internet Todalanet
Re: Code for adding RSS to every forum and subforum
« Reply #3 on: May 17, 2006, 02:02:14 PM »
This is the code I use for adding the RSS-link at the end of the breadcrumbs. Put this code at the end of function theme_linktree() inside index.template.php:
Code: [Select]
// Print RSS link if it is turned onon
if (!empty($modSettings['xmlnews_enable'])) {
echo '<div style="float: left; background-color: #f90; font-size: 9px; border: 1px solid #fc0; padding: 0px 2px;; line-height: 1em;">';
if ($_REQUEST['board']) {
$spotnumber = count($context['linktree'])-1;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
} elseif ($_REQUEST['topic']) {
$spotnumber = count($context['linktree'])-2;
$rss_title = $context['linktree'][$spotnumber]['name'];
echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
} else {
echo '<a title="Kampforum RSS: 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';
}
echo 'RSS</a>';
echo '</div>';
}


Hi,
I tried to add the code to my index template and it didn't work.

I also tried a modification of this:
// Show the link, including a URL if it should have one.
echo ($link_num != count($context['linktree']) - 1) ? '' : ' <a title="RSS ' . $context['page_title'] . '" type="application/rss+xml" href="' . $scripturl . '?type=rss;action=.xml" /><img src="/rss_delforo.png" valign="middle" hspace="2"  border="0" /></a><b> ', $settings['linktree_link'] && isset($tree['url']) ? '<a href="' . $tree['url'] . '" class="nav" title="' . $tree['name'] .'" />' . $tree['name'] . '</a>' : $tree['name'], ($link_num != count($context['linktree']) - 1) ? '' : '</b>';

But it just keeps it throwing the same url.
Anyone know how to insert this code in my linkthree? I tried some modifications but I keep doing it wrong!

if ($_REQUEST['board']) {
         $spotnumber = count($context['linktree'])-1;
         $rss_title = $context['linktree'][$spotnumber]['name'];
         echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';         
      } elseif ($_REQUEST['topic']) {
         $spotnumber = count($context['linktree'])-2;
         $rss_title = $context['linktree'][$spotnumber]['name'];
         echo '<a title="Kampforum RSS: '.$rss_title.' - 20 latest" href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context['current_board'].';limit=20" style="font-weight: normal; text-decoration: none; color: #fff;">';      

Offline moonwolf

  • Newbie
  • *
  • Posts: 8
  • Gender: Female
Re: Code for adding RSS to every forum and subforum
« Reply #4 on: May 17, 2006, 07:36:56 PM »
in Themes/<themename>/index.template.php

Find:
Code: [Select]
function theme_linktree()
{
        global $context, $settings, $options;   

Replace with:
Code: [Select]
function theme_linktree()
{
        global $context, $settings, $options, $modSettings;   

there's a conditional at the start of adding the RSS link to the bottom of the linktree based on whether or not XML is turned on or off in the settings, but the conditional couldn't check $modSettings as it wasn't being declared in the globals at the start of the function.  this fixes it.
hxxp:creativecommons.org/licenses/by-nc-sa/2.5/ [nonactive]
Original code, patches, and fragments by the author are  licensed under a hxxp:creativecommons.org/licenses/by-nc-sa/2.5/ [nonactive].
Just a pity that even has to be said.

Offline Uzbekistan

  • Jr. Member
  • **
  • Posts: 129
    • Uzbekistan Forum
Re: Code for adding RSS to every forum and subforum
« Reply #5 on: July 27, 2006, 07:34:35 AM »
Hi guys, is this trick going to work on SMF 1.1 RC2?

The code of torkil shows link
Code: [Select]
...href="http://www.kampforum.com/forum/index.php?action=.xml;type=rss;sa=recent;board='.$context...
However the RSS link on the SMF 1.1 goes
Code: [Select]
http://www.uzforum.com/index.php?type=rss;action=.xml . Is it the same?

Offline torkil

  • Jr. Member
  • **
  • Posts: 126
  • Gender: Male
Re: Code for adding RSS to every forum and subforum
« Reply #6 on: July 27, 2006, 07:56:13 AM »
No, my code is to get a feed from a specific board. The code you have there looks like a more general one, for the entire forum I think.

Offline Uzbekistan

  • Jr. Member
  • **
  • Posts: 129
    • Uzbekistan Forum
Re: Code for adding RSS to every forum and subforum
« Reply #7 on: July 27, 2006, 05:59:41 PM »
Hmm.. I just copied a line from your code :).

The question is different - does it work with SMF 1.1 RC2? Coz the dates of your code  old - for SMF 1.0.

Offline Vinspire

  • Sr. Member
  • ****
  • Posts: 852
  • Gender: Male
    • The Box Of Heart Forum
Re: Code for adding RSS to every forum and subforum
« Reply #8 on: July 28, 2006, 02:00:34 AM »
Hmm.. I just copied a line from your code :).

The question is different - does it work with SMF 1.1 RC2? Coz the dates of your code  old - for SMF 1.0.

I 2nd this :)

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,604
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Re: Code for adding RSS to every forum and subforum
« Reply #9 on: July 29, 2006, 08:42:50 AM »
I think RSS feeds should be built in SMF and the user should be able to acticate them from Admin and of course one should be able to subscribe to a forum / category / board / topic feed. I find it really strange why such a basic feature as this is not there yet.

Offline theshown

  • Semi-Newbie
  • *
  • Posts: 75
Re: Code for adding RSS to every forum and subforum
« Reply #10 on: October 01, 2006, 03:02:46 PM »
can anyone post a link to a forum in which this trick work correclty? possibly a forum which runs versione SMF 1.1 rc3  :(
My Projects: SOLDAT Italia

Offline Uzbekistan

  • Jr. Member
  • **
  • Posts: 129
    • Uzbekistan Forum
Re: Code for adding RSS to every forum and subforum
« Reply #11 on: October 11, 2006, 06:05:33 AM »
Just trying to revive this topic... ;)

C'mon guys! How many minutes/hours of coding is required for this? Maybe we can spice it up by donations? Sadly I am not a programmer...

The feature described by spiros is common nowadays in software of such a size. It's a shame smf hasn't got it.

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,604
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Re: Code for adding RSS to every forum and subforum
« Reply #12 on: October 11, 2006, 07:29:14 AM »
can anyone post a link to a forum in which this trick work correclty? possibly a forum which runs versione SMF 1.1 rc3  :(

http://virtuemart.net/index.php?option=com_smf&Itemid=71