开发者

capture current view and change displayed records drupal

开发者 https://www.devze.com 2023-02-05 08:33 出处:网络
I want to capture the current view and change the number of items it displays using hook_views_query_alter()

I want to capture the current view and change the number of items it displays using hook_views_query_alter()

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

$itemcount = $_GET['itemcount']; 

//$url = $_SERVER['REQUEST_URI'];

if ($itemcount == 25) {

    $view = views_get_current_view();

   开发者_运维知识库 $view->set_items_per_page(25);
}
elseif($itemcount == 50){
    $view = views_get_current_view();
    $view->set_items_per_page(50);
}
elseif($itemcount == 100){
    $view = views_get_current_view();
    $view->set_items_per_page(100);
}
}

However it does not capture the current view


By the time hook_views_query_alter() is called, it may be too late to change the number items using that method. You may look into trying this in one of the other available hooks (particularly hook_views_pre_view, hook_views_pre_build or hook_views_pre_execute).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号