Hi,

I'm trying to place a link to my RSS feeds (generated by views_rss) in a sidebar block. I have the RSS icon below the view, so could manually link to each specific node, but I don't want to have to do this for each view produced. I'm no good with php, so was wondering if you could suggest some code that could achieve this?

So basically I either want to remove the RSS icon from below the view and place it in a block instead, or want a way of creating a dynamic link to the feed URL that could be used in a block (with or without the RSS icon below the view).

I hope that just about makes sense. The solution is no doubt simple, but I just cannot figure it out!

Comments

edpaff’s picture

Just to follow up...

It seems that the views_rss module prints its feed icons through page.tpl.php. The feed icons are printed through this code <?php print $feed_icons; ?> but when you try to enter this code in a block it doesn't seem to work.

Can anyone suggest any alternative?

merlinofchaos’s picture

In your block-view.tpl.php you can try this:

Note. This is untested, so you may have to fiddle with it a bit.

  $view = views_get_current_view(); 
  // If this doesn't work, try global $current_view; $view = $current_view;
  $args = views_post_view_make_args($view, 'rss_feed', 'feed');
  $url = views_get_url($view, $args);
  $title = views_get_title($view, 'block', $args);
  print theme('feed_icon', $url, $title);
edpaff’s picture

Thanks for the reply,

Have given it a go, and unfortunately have had no luck. Have fiddled as suggested but am getting an error:

warning: Invalid argument supplied for foreach() in /home/mysite/public_html/mysite/modules/views/modules/views_node.inc on line 846.

The feed icon shows, but the link is to the page URL rather than the RSS URL...

Thanks again for trying.

Florent Jousseaume’s picture

Hi

I just find a solution for this problem.

After searching why this snippet does not work, I find with the debug module. When you have more than 1 block generated by the view module, the current_view variable is not the block view's...

Here is my soluce

<?php
  $myview = views_load_view($block->delta);
  $args = views_post_view_make_args($myview, 'rss_feed', 'feed');
  $url = views_get_url($myview, array( 'feed') );
  $title = views_get_title($myview, 'block', $args);
  print theme('feed_icon', check_url(url($url)), $title);
?>

It perhaps exists a simpler soluce, but it works fine for this case :)

Florent,

Scott.Champion’s picture

Hi you guys,

I'm having the same issue. I want to make the Syndicate link on each page access the RSS feed generated by Views. I'm new to drupal and tried to find the file you're talking about "block-view.tpl.php" in a search and didn't find it. I added it to my theme's directory, but it hasn't had any effect.

I'm using a derivative of the zen theme. Can you help me get my bearings?

Thanks so much, in advance!

Scott,

Florent Jousseaume’s picture

Hi,

This file doesn't exist by default. You can copy the block.tpl.php with the name block-view.tpl.php

All blocks generated from a view would be concerned by this template, so you can apply a different treatment.

I hope it helps you

Florent,

(I was on holidays before, sorry for the later) (sorry for my english too !)

sun’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

merilainen’s picture

Is this working? I cannot get it to show the feed icon inside my block. When I open the full page view, there is the feed icon showing up as it should.

Andrey Zakharov’s picture

Version: 5.x-1.6 » 6.x-2.11
Issue tags: +howto, +solved

My solution for Views 6.x-2.x


  $myview = views_get_view( 'latest_news' ); ///< Your views ID or name here
  $display = 'feed_1'; ///< Your feed name here, string used 2 times
  $myview ->set_display( $display );
  //$args = array(); ///< You can provide view by some arguments
  //$myview ->set_arguments( $args );
  $url = $myview ->get_url();
  $title = $myview ->display[ $display ]->display_options[ 'title' ];
  print theme( 'feed_icon', check_url( url($url) ), $title );

anou’s picture

And here's the code for Drupal 7 :

 <?php
  $myview = views_get_view( 'my-view' ); ///< Your views ID or name here
  $display = 'feed_1'; ///< Your feed name here, string used 2 times
  $myview  ->set_display( $display );
  //$args = array(); ///< You can provide view by some arguments
  //$myview  ->set_arguments( $args );
  $var['url'] = $myview ->get_url();
  $var['title'] = isset($myview ->display[ $display ]->display_options[ 'title' ]) ? $myview ->display[ $display ]->display_options[ 'title' ] : t('feed'); //< if title not set, set a default one

  print theme( 'feed_icon', $var );
?>