News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Code for adding RSS to every forum and subforum

Started by torkil, June 03, 2005, 03:57:11 AM

Previous topic - Next topic

torkil

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:

// 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:

// 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.

torkil

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:

// Show an xml file representing recent information or a profile.
function ShowXmlFeed()
{
global $context, $scripturl, $txt, $modSettings;


with the following:

// 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:

if ($xml_format != 'smf')
{


To this:


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
<title>', strip_tags($context['forum_name']), '</title>

To this:
<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

spiros

#2
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


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


Quote from: torkil 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:

// 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:

// 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.

carlatf

Quote from: torkil on June 03, 2005, 03:57:11 AM
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:

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

moonwolf

in Themes/<themename>/index.template.php

Find:

function theme_linktree()
{
        global $context, $settings, $options;   


Replace with:

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.

Uzbekistan

Hi guys, is this trick going to work on SMF 1.1 RC2?

The code of torkil shows link ...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 http://www.uzforum.com/index.php?type=rss;action=.xml . Is it the same?

torkil

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.

Uzbekistan

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.

Vinspire

Quote from: Uzbek 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.

I 2nd this :)

spiros

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.

theshown

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

Uzbekistan

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.

spiros

Quote from: theshown 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  :(

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

Advertisement: