Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: torkil in Juni 03, 2005, 03:57:11 VORMITTAG

Titel: Code for adding RSS to every forum and subforum
Beitrag von: torkil in Juni 03, 2005, 03:57:11 VORMITTAG
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 (http://www.simplemachines.org/community/index.php?topic=37646.0) to get help to fix that.
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: torkil in Juni 03, 2005, 07:34:28 VORMITTAG
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
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: spiros in Juni 25, 2005, 09:03:08 VORMITTAG
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>


Zitat von: torkil in Juni 03, 2005, 03:57:11 VORMITTAG
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 (http://www.simplemachines.org/community/index.php?topic=37646.0) to get help to fix that.
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: carlatf in Mai 17, 2006, 02:02:14 NACHMITTAGS
Zitat von: torkil in Juni 03, 2005, 03:57:11 VORMITTAG
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;">';      
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: moonwolf in Mai 17, 2006, 07:36:56 NACHMITTAGS
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.
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: Uzbekistan in Juli 27, 2006, 07:34:35 VORMITTAG
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?
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: torkil in Juli 27, 2006, 07:56:13 VORMITTAG
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.
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: Uzbekistan in Juli 27, 2006, 05:59:41 NACHMITTAGS
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.
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: Vinspire in Juli 28, 2006, 02:00:34 VORMITTAG
Zitat von: Uzbek in Juli 27, 2006, 05:59:41 NACHMITTAGS
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 :)
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: spiros in Juli 29, 2006, 08:42:50 VORMITTAG
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.
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: theshown in Oktober 01, 2006, 03:02:46 NACHMITTAGS
can anyone post a link to a forum in which this trick work correclty? possibly a forum which runs versione SMF 1.1 rc3  :(
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: Uzbekistan in Oktober 11, 2006, 06:05:33 VORMITTAG
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.
Titel: Re: Code for adding RSS to every forum and subforum
Beitrag von: spiros in Oktober 11, 2006, 07:29:14 VORMITTAG
Zitat von: theshown in Oktober 01, 2006, 03:02:46 NACHMITTAGS
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