0

I have a RSS feed being built by the Views RSS module. I can configure the pager to display a certain number of items; however, some consumers of my feed only want a few of my latest items from my feed. So I need to pass a limit in the URL to the number of items in my feed. something like this:

www.mywebsite.com/rsslatestnews/50 - For 50 items.
or
www.mywebsite.com/rsslatestnews/2 - For 2 Items.

I've tried implementing the hooks:

  • hook_views_pre_build
  • hook_views_post_build
  • hook_views_pre_execute
  • hook_views_post_execute
  • hook_views_pre_render
  • hook_views_post_render

To no avail, I think the RSS Views module is in some way skipping the typical order views hooks are triggered.

My question is this:

Which hook can I use to set the limit of items displayed by my RSS view?

0
/**  
 * Implements hook_views_query_alter.
 *  
 * If we have an rss feed view we need to set pager settings from url.  
 * If no pager number specified in the url do nothing and use view pager   settings.
 * Otherwise get the items_per_page options from the first argument in the url.  
 */

function rss_feed_length_views_query_alter(&$view, &$query) {

  $rss_views = array(
    'rss',
  );

  if (in_array($view->name, $rss_views)) {
    $limit = arg(1);
    if ($limit !== NULL) {
      $view->set_items_per_page($limit);
    }
  }
}

SUGGESTED IMPROVEMENT:

"i'd have used GET parameters rather than path elements - since it's not a different resource, rather it's an option"

I'll accept as an answer anything that implements the suggested improvement. :)

  • I don't get it. Did you solve your problem or not? – Codium Mar 7 '16 at 17:10
  • yes I did but there is a better solution using get parameters. – iain maitland Mar 7 '16 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.