Hey everyone,

I started getting my site working with Drupal and having fun :-).

One thing I wanted was to have my RSS feed for my blog available on all pages of my site through a little icon in the bottom right hand corner of the page. Is there an easy way to achieve this at all?

Cheers,
Matt

Comments

grobemo’s picture

Basically, you want to find the HTML for the RSS feed button and add it (or some PHP that generates it) to your theme's page.tpl.php. (If you have other versions of page.tpl.php, like page-front.tpl.php, you'll need to add it there, too.) That will make it show up on every page of your site.

mattgaunt’s picture

Thanks for the reply grobemo.

I am guessing the variable that was being used was $feed_icons (from http://drupal.org/node/11812) but this is blank now :-S

Anyway I wanted to have one main RSS feed which had the titles and teasers of my blog, which isn't the page which has been promoted to the front page, so I dont want to start looking into how to edit the $feed_icons function is its not the right place, because I know there is a feed item at /rss.xml but that is the front page.

So can anyone point me in the direction of some reading material, I have searched around but couldn't find anything similar to what I'm trying to achieve but I am sorry if it has been answered many times before.

grobemo’s picture

Actually, I meant it literally when I said "find the HTML for the RSS feed button" and paste that into your page.tpl.php. I looked into the actual code, and it should look something like this:

<a href="<?php print base_path(); ?>blog/YOUR-UID-GOES-HERE/feed" class="feed-icon"><img src="<?php print base_path(); ?>misc/feed.png" alt="Syndicate content" title="RSS - YOUR-USER-NAME-GOES-HERE blog" width="16" height="16" /></a>

This should suffice if it's just for your own site (i.e., not for a client who might want to change the uid through the browser). If you really want to, you could create a variable like $blog_feed in your YOURTHEME_preprocess_page function in template.php, but that would only be necessary if you have multiple page templates (e.g., page.tpl.php and page-front.tpl.php), and you want this on more than one of them.

And IMHO, the <img> tag is not semantically ideal. I'd take that out and just do a CSS background-image.

mattgaunt’s picture

ooo ok, I'll look into it with the blog etc cheers.

I would of liked to of found a way to of dynamically added the blog feed just because I'm trying to do all this as I may use Drupal with some clients.

But thank you so much for you advice and getting my started, I may have a play around with adding it in the variables.

grobemo’s picture

I just thought of an alternative that you might consider. If create a custom block (Administer > Site building > Blocks) that contains the HTML above (or some PHP to generate it), you could easily stick that block on every page. You could even do some processing in the block to dynamically decide which blogs to include.

If you do work out a more dynamic solution, be sure to post it back here for other users.

Jeff Burnz’s picture

function themeNAME_preprocess_page(&$vars, $hook) {
  $icon = theme('image', 'misc/feed.png', t('RSS'), t('RSS Feed'));
  $vars['blog_feed'] = l($icon, 'path-to-blog-feed', array('attributes' => array('class' => 'feed-icon')));
}

// conditionally print variable in page templates
<?php if ($whatever && $blog_feed) : ?>
  <div class="blog-feed-icon"><?php print $blog_feed; ?></div>
<?php endif; ?>
mattgaunt’s picture

Thank you for the replies.

I'll have a look into the blocks and jmburnz's method.

Cheers,
Matt

mattgaunt’s picture

Ok so I couldn't really think of a way of getting this to work the way I wanted. jmburnz your method worked after a little changing to make it take html TRUE in the array for l(), but I also wanted to have the blog feed URL so the RSS icon appears in the address bar of browsers (i.e. <link rel="alternate" type="application/atom+xml" title="Atom" href="/blog/feed" />)

So for now I've added it in statically till I get my head around how Drupal deals with blog's etc because at the moment I just seem to be fighting against the way Drupal does things which I'm sure is just because I am not following how it works.

grobemo’s picture

I've done a little Drupal work with RSS since you posted this. I think drupal_add_feed does what you want.