Sunday, November 20, 2011

Drupal 6 Pages and Feed RSS: set the offset and item's pagination.



If you have to change dinamically the number of items that are displayed on your feed page or do you need to set their offset via Drupal 6 Feed Rss Views Module, than this post could helps.

After googling for a couple of hours without find any solution to this issue, i tried to solve it by myself.
I would like to pass custom number of items and their offset as arguments of an url.

Something like this

http://www.yourdrupalwebsite.com/rss.xml?items-limit=5&items-offset=5

This page is a custom feed page created by the drupal's admin side .



/admin/build/views/edit/(rss-feed) (in my case)


After that you'll have to use this little hack that change a little piece of code inside the file

modules/views/plugins/views_plugin_display.inc

I found this piece of code on the line 1861. So i changed the following default settings:


$this->view->set_pager_element($this->get_option('pager_element'));$this->view->set_items_per_page($this->get_option('items_per_page'));
$this->view->set_offset($this->get_option('offset'));



and i replaced them with:


$this->view->set_items_per_page(($_GET['items-limit'] > 0) ? $_GET['items-limit'] : $this->get_option('items_per_page'));
$this->view->set_offset(($_GET['items-offset'] > 0) ? $_GET['items-offset'] :$this->get_option('offset'));



Save the file and you'll be ready to call your feed page with your custom arguments with it.

http://www.yourdrupalwebsite.com/rss.xml?items-limit=5&items-offset=5


and check the response.


Note:
You need to filter and sanitize your $_GET input values for security reasons.



Enjoy














No comments: