0

Is there a way to add a Show All Link on my view pager.

I have a Block View.

I would like to be able to add an All Link button when the number of Items reach 5. I do not need the pager "Next, last 1,2,3" only the All Link button.

Thanks a lot

  • see my edit(s) to my answer. – tenken Jul 14 '14 at 22:22
0

Yes see the Pager Options for your Block or Views Page:

enter image description here

EDIT:

Allow me to clarify. This gets the - All - text option into the configuration of the View. If you want custom business logic that says if there is 5 or more results I want to show/hide the Next and Previous and include the All options I recommend you look at hook_views_pre_view() or other Views hooks to implement hiding/removing options as needed. For ease I recommend hiding/showing the options using CSS or Javascript.

Again, this option builds the option into the page -- but doesn't really enforce your business logic.

EDIT 2:

The module Pagerer might get you a little further, but probably not all of your custom logic is possible out of the box with that module. It has an API to fine-grain it's custom pager views.

| improve this answer | |
  • Can you provide me a sample code for Edit One. ? – Jean-Francois Jul 15 '14 at 2:19
0

If you want to do this via coding then this can be helpful to you. I've used this in my own projects.

  1. Add a new file with ".views.inc" extension. Preferred module_name.views.inc.
  2. Theme the block form and add a variable to the views output via HOOK views_pre_render.
  3. Then with the HOOK_pre_build function you can modify the pager items per page.

function MYMODULE_views_pre_render(&$view) {
  if ($view->name = 'your_view') {
    $view->attachment_after['show_all'] = l('Title', 'show-all', array('query' => array('view_name' => $view->name)));
  }
}


function MYMODULE_views_pre_build(&$view) {
  if ($view->name == 'your_view' && (isset($_GET['view_name']) && $_GET['view_name'] == $view->name)) {
    if (arg(0) == 'show-all') {
      $view->pager['items_per_page'] = 200; //The number you want to have.
    }
  }
}

| improve this answer | |
  • I try MYMODULE_views_pre_build and it's never firing up. To be sure that is not called, I create a txt file when this method is called – Jean-Francois Jul 18 '14 at 19:58
  • have you cleared the cache?? – Aneek Mukhopadhyay Jul 20 '14 at 16:46
  • Yes I do. I'm using Omega 4. Is it possible that it could cause thé problem to not firing up thé prebuild hook – Jean-Francois Jul 22 '14 at 10:11
  • This has nothing to do with the theme you are using. Check about the function name and spelling. If your module is called "foo_mod" then the hook will be function foo_mod_views_pre_build(&$view) {} Please check and let me know. – Aneek Mukhopadhyay Jul 22 '14 at 13:12

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.