Hello,

I have searched for this online but couldn't get it working.

I have a view that I use for showing different items on my website. It is a very simple view that accept taxonomy term as argument and shows the related nodes.

This view also have a pager, that handle 20 items per page.

I want to see if it is possible to dynamically change that to another number, for example if we are in different category (taxonomy term), I want to show different items per page.

I have tried achieving this by hook_views_pre_build or hook_views_pre_execute but no chances yet!

Anyone can help please?

Comments

damiankloip’s picture

Sorry, I'm not sure I understand what you are trying to do dynamically that contextual filters can't handle mormally?

damiankloip’s picture

oh, you want to change the amount of items per page dunamically!? Sorry, just got it :)

dawehner’s picture

I have tried achieving this by hook_views_pre_build or hook_views_pre_execute but no chances yet!

How did you tried to do that?

Something like that should probably work:

function hook_views_pre_execute(&$view) {
  $view->init_pager();
  $view->set_items_per_page($number);
}
damiankloip’s picture

I think dawehner is right there, but you might need to use hook_views_pre_build instead to get it working?

damiankloip’s picture

Status: Active » Fixed

I'm going to say this is fixed. The advice in the 2 comments above will work for setting the items per page.

WoozyDuck’s picture

Thank you very much

Status: Fixed » Closed (fixed)

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