1

We have created a view, myview, where we want to display 3 nodes (content type = basic) and add a View All button on page load. The purpose of the 'View All' button will be to show 6 more (the view is supposed to show max 9).

How can we display 3 nodes with a View All button?

What we tried, but the view did not display the view all button nor did it allow me to limit to total of 9. I also could not find an appropriate view hook to do what i am looking for.

View settings:

  • Change pager plugin to full
  • change pager plugin to mini
2

Looks like Views Infinite Scroll is a good option for you:

Views infinite scroll allows you to load and display pages of any view inline, using AJAX (this has been called infinite scrolling, load more, autopaging, endless pages and more). The pager can be triggered with the press of a button or automatically as the user scrolls to the bottom of the view's content.

Here's the pager settings: enter image description here

1

There are more ways of solving it depending on your circumstances.

The obvious way is through 2 views displays with different paths, or as parent-child path3 for the first one and path3/path9 for the second one (you can set them as Drupal tabs that way, so Drupal tab can play the role of your button "Show 6 more"). Set one to only show 3 items, the other one to show 9. Add a text area in the Views Footer of your first display and add the anchor HTML that leads to the page link of your second views display.

If you know a bit of Ajax you could display one of the displays as an attachment that has pager offset set to 3, and use Ajax button to make it display.


You can allow users to choose how many items are displayed by Exposing the Full or Mini pager with the option Allow user to control the number of items displayed in this view and enter 3, 9 while setting Items per page to 3.

This way you will see 3 items to start with, but there will be a dropdown above your results where users can choose either 3 or 9. If they choose 9 the page will reload to show 9 items in the results.

Using the Pager this way also gives you parameters on your links so you can even build links/button elsewhere on your site to link to a page with a particular number of results path3?items_per_page=9.

The downside for you may be that there are also pager links at the bottom of the results (Previous, Next) that you might not want displayed. Maybe you can hide them with CSS.

You should also research into the Pager related modules, maybe Views flexible pager and Pagerer can help.

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.