In 'Views Show More' module exist useful feature which allows us to change amount of initial items on page.

For example: we can have 3 items when page first loads, and after pressing 'Load more' button we will get like 6 item each time.

I needed this functionality on one of my projects, so here is a patch for that.

CommentFileSizeAuthor
#78 Add-Page-Control-2852080-#78.patch10.69 KBmugesh.s
#76 Add-Page-Control-2852080-#76.patch9.85 KBmugesh.s
#69 views_infinite_scroll-2852080-69.patch5.6 KBypx
#61 views_infinite_scroll-2852080-60.patch13.02 KBchristiansanders
#60 views_infinite_scroll-2852080-60.txt13.02 KBchristiansanders
#60 interdiff-2852080-60-56.txt1.26 KBchristiansanders
#59 2852080-59.patch1.32 KBchristiansanders
#59 interdiff_2852080-59.txt6.27 KBchristiansanders
#56 2852080.patch6.38 KBerik_petra
#55 different_item_count-2852080-55.patch6.72 KBhimanshu_jhaloya
#52 2852080-52.patch7.37 KBAnonymous (not verified)
#51 different_item_count-2852080-50.patch17.09 KBlobodakyrylo
#49 interdiff-2852080-48-49.txt782 bytesYurkinPark
#49 different_item_count-2852080-49.patch17.09 KBYurkinPark
#48 different_item_count-2852080-48.patch16.94 KBYurkinPark
#47 2852080-46.patch18.51 KBmaithri shetty
#46 2852080-46.patch18.51 KBmaithri shetty
#43 13433832-60+2852080-40.patch26.93 KBAnonymous (not verified)
#42 13433832-59+2852080-40.patch26.83 KBAnonymous (not verified)
#41 interdiff_37-40.txt1.82 KBAnonymous (not verified)
#40 different_item_count-2852080-40.patch15.77 KBAnonymous (not verified)
#38 different_item_count-2852080-38.patch22.98 KBAnonymous (not verified)
#37 different_item_count-2852080-37.patch14.85 KBAnonymous (not verified)
#36 interdiff-2852080-32-36.txt1.58 KBYurkinPark
#36 different_item_count-2852080-36.patch14.11 KBYurkinPark
#32 2852080-32.patch13.35 KBandypost
#32 interdiff.txt2.34 KBandypost
#30 interdiff_2852080_25_30.txt9.39 KBYurkinPark
#30 different_item_count-2852080-30.patch13.5 KBYurkinPark
#25 different_item_count-2852080-25.patch3.36 KBgaydamaka
#24 different_item_count-2852080-24.patch3.36 KBskylord
#15 different_item_count-2852080-15.patch3.3 KBpiggito
#14 different_item_count-2852080-14.patch2.96 KBdiegodalr3
#9 different_item_count-2852080-9.patch2.95 KBandypost
#9 interdiff.txt1.78 KBandypost
#4 add_Initial_items_options_to_pager_settings-2852080-2.patch2.37 KBtarasich
add_Initial_items_options_to_pager_settings.patch2.36 KBtarasich
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tarasich created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
andypost’s picture

+++ b/src/Plugin/views/pager/InfiniteScroll.php
@@ -90,7 +93,53 @@ class InfiniteScroll extends SqlBase {
+        '#title' => t('Initial items'),
+        '#description' => t('The number of items to display initially. Enter 0 for use same as items per page (show more click).'),
...
+      $form_state->setError($element, t('%name must be a positive integer.', array('%name' => $element['#title'])));

this should be $this->t() because inside pluigin

tarasich’s picture

Thanks @andypost!
D7 habits)
Changed everywhere except static method

tarasich’s picture

Hide old one

The last submitted patch, add_Initial_items_options_to_pager_settings.patch, failed testing.

The last submitted patch, add_Initial_items_options_to_pager_settings.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: add_Initial_items_options_to_pager_settings-2852080-2.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.78 KB
new2.95 KB

Fix tests

The last submitted patch, add_Initial_items_options_to_pager_settings.patch, failed testing.

The last submitted patch, add_Initial_items_options_to_pager_settings.patch, failed testing.

tarasich’s picture

sam152’s picture

Status: Needs review » Needs work

This seems pretty out of the 80% use case, for a module that already has a hard time keeping up with bare minimum compatibility with the rest of the views features and touch points. Maybe some test cases could be added to prove this works, but I can't say I really think this should be part of the base module.

+++ b/src/Plugin/views/pager/InfiniteScroll.php
@@ -90,7 +92,52 @@ class InfiniteScroll extends SqlBase {
+        '#type' => 'textfield',
...
+  public static function validateIntegerPositive(array &$element, FormStateInterface $form_state, array &$complete_form) {
+    $value = $element['#value'];
+    if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value < 0)) {
+      $form_state->setError($element, t('%name must be a positive integer.', array('%name' => $element['#title'])));
+    }
+  }

We can use a number type here with a #min/#max?

diegodalr3’s picture

StatusFileSize
new2.96 KB

Fix offset option.

piggito’s picture

StatusFileSize
new3.3 KB

This patch had an issue concerning pager, the default pager assumes all pages have the same number of elements. I added a getPagerTotal override method to solve this issue with the pager.

piggito’s picture

Status: Needs work » Needs review
sam152’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
Anonymous’s picture

This should be in the module. It's related to infinite pagers and shouldn't be fragmented off to its own world.

sam152’s picture

Status: Needs work » Closed (won't fix)

I disagree. There is already a large volume of bugs and support requests that come up for the basic functionality. If the decision was made to allow every edge case into the module, it would be less maintainable than it already is. As of now, the functionality adds complexity, isn't tested and isn't appropriate for the 80%. Closing.

Anonymous’s picture

Status: Closed (won't fix) » Active

Huh? You have people here requesting this as a feature. Closing this is really inappropriate.

andypost’s picture

Assigned: tarasich » Unassigned
Status: Active » Needs work

Let's set proper status - this issue no-go to becommited without tests

PS: I'm using the patch a lot and it works fine

sam152’s picture

Closing this is really inappropriate.

It's actually a perfectly reasonable product management decision. Maintainer aren't obliged to commit feature requests.

waspper’s picture

After testing the patch, I've seen it works well. IMHO, it's a valid feature request for several use cases, keeping in mind that patch is almost ready.

I've tested it with several views, displaying ViewModes or Fields, and at least at my side, no errors found, with several Drupal versions.

skylord’s picture

StatusFileSize
new3.36 KB

Small fix for edge cases in total items counting.

gaydamaka’s picture

StatusFileSize
new3.36 KB

Fix patch after update dev version.

elaman’s picture

As it was stated before, this feature might be a game changer. Most of the people will module as it is, but there are times you need to show couple of items, then load much more.
I think it should also be possible to set initial number of values to zero. This could be used as "spoiler" feature to display attachments, etc.

nally’s picture

We are seeing a client request for this specific case, so consider this an upvote for including it in the main version of the module if you do have the time.

Thanks for your maintenance efforts! We appreciate it.

renrhaf’s picture

+1 : Using patch from #9, works perfectly on latest Drupal version.
This use case seems to be pretty useful for some people !
Thank you for your work on the cool module.

Anonymous’s picture

Found a bug with patch from #9: If you have f. ex. 7 items, and you set the initially loaded items to 5, the load more link won't appear. E.a. if the number of remaining results is less than the "initial" setting introduced by this patch, you will not be able to fetch the last results.

Edit: This has been fixed with patch from #15.

YurkinPark’s picture

StatusFileSize
new13.5 KB
new9.39 KB

Tests, updates for existing instances

YurkinPark’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests
StatusFileSize
new2.34 KB
new13.35 KB

Minor codestyle fixes

tostinni’s picture

Thank you for this patch, working fine and very useful.

However I noticed a small bug, if the views doesn't have enough items to load the first page, and the "initial items" variable is set to 0 to get the same number as the following pages then the load more button is shown even if there's no more pages.
Setting "initial items" to the same value as "Items to display" will fix this.

Also "Initial items" could be a number field instead of a text field.

honza pobořil’s picture

Nice work.

I am going to commit it when this will be solved:

However I noticed a small bug, if the views doesn't have enough items to load the first page, and the "initial items" variable is set to 0 to get the same number as the following pages then the load more button is shown even if there's no more pages.
Setting "initial items" to the same value as "Items to display" will fix this.

Also "Initial items" could be a number field instead of a text field.

honza pobořil’s picture

Status: Reviewed & tested by the community » Needs work
YurkinPark’s picture

Status: Needs work » Needs review
StatusFileSize
new14.11 KB
new1.58 KB

@bobík it is resolved now

Anonymous’s picture

StatusFileSize
new14.85 KB

Found another bug with the latest patch (36): the @next_page_count token is incorrect if initial option is another other than zero. Updated patch attached.

Anonymous’s picture

StatusFileSize
new22.98 KB

It appears that in the latest version of Drupal (8.8.1) the getPagerTotal() method is no longer used. Therefore the calculation of the total number of pages is no longer correct. I've attached a new patch. Feel free to comment/improve.

andypost’s picture

Last patch is broken, also please attach interdiff of you changes from 36 to help reviewers follow your changes

Anonymous’s picture

StatusFileSize
new15.77 KB

sorry about that, I included the patch itself in my patch. attached should be correct patch.

Anonymous’s picture

StatusFileSize
new1.82 KB

interdiff

Anonymous’s picture

StatusFileSize
new26.83 KB

Also needed the functionality of #2667516 so I've added a patch that combines the latest patch in that issue and the one above.

Anonymous’s picture

StatusFileSize
new26.93 KB

Made a mistake in patch above, here's a correct one. Again, this is only for when you need the functionality in issue #2667516 and the one from this ticket.

neslee canil pinto’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
maithri shetty’s picture

Assigned: Unassigned » maithri shetty
maithri shetty’s picture

Status: Needs work » Needs review
StatusFileSize
new18.51 KB
maithri shetty’s picture

StatusFileSize
new18.51 KB
YurkinPark’s picture

Assigned: maithri shetty » Unassigned
Issue tags: -Needs reroll +Needs tests
Related issues: +#2972129: Add option to initially load all pages up to the requested page when loading pages beyond the first
StatusFileSize
new16.94 KB
YurkinPark’s picture

Issue tags: -Needs tests
StatusFileSize
new17.09 KB
new782 bytes

I think this is final version

mturner20’s picture

I am on 8.8.x and patch #37 applied successfully!

lobodakyrylo’s picture

StatusFileSize
new17.09 KB

Since the last update different_item_count-2852080-49.patch doesn't work anymore. Here a new patch.

Anonymous’s picture

StatusFileSize
new7.37 KB

Here's one that works with 1.8 and the latest patch of this issue: https://www.drupal.org/node/2667516

kevin.pfeifer’s picture

Is there a patch for D9.3 as well?
The patch from #52 can be applied and I see the new input field in the pager options but on AJAX Views this doesn't result in the desired behavior that I want to define a different amount of intially shown items vs the amount of items loaded after clicking the "Load more" button.

himanshu_jhaloya’s picture

Hi I am looking patch for D9 is there any patch for this same issue version 2.0.1

himanshu_jhaloya’s picture

Version: 8.x-1.x-dev » 2.0.1
StatusFileSize
new6.72 KB

Created patch for D9

erik_petra’s picture

StatusFileSize
new6.38 KB

Patch at #55 did not apply successfully for me through composer patches, so I fixed it and also fixed some formatting. Patch is for 2.0.2, due to Drupal 10 upgrades.

anybody’s picture

Version: 2.0.1 » 2.0.x-dev
Issue tags: +Needs tests
christiansanders’s picture

Unfortunately the latest patch (comment #56) isn't working as desired.

I have a view with 9 results.

Initially set to display 7 and load 6 thereafter.

The initial items of 7 display, but because my view results don't have enough results to reach an additional 6 (9 results, 7 of initial page load, therefore 2 more to load in) the pager doesn't load.

I've tested by changing initially show 4 items and then 3 thereafter on load. The pager displays, loads in my 3, then no more pager, cause I have 2 items left, not 3.

This is all tested via AJAX.

christiansanders’s picture

StatusFileSize
new6.27 KB
new1.32 KB

Added a patch that solves my comment in 58.

christiansanders’s picture

Uploaded the files the wrong way around perviously - sorry!

christiansanders’s picture

StatusFileSize
new13.02 KB
anybody’s picture

Thanks @ChristianSanders could you prepare that as MR perhaps, please?

christiansanders’s picture

@Anybody done - https://git.drupalcode.org/project/views_infinite_scroll/-/merge_request... (hope i've done this correctly - this is my first time contributing a patch via an MR!) Thanks :)

anybody’s picture

Status: Needs review » Needs work

Thanks @ChristianSanders. Looking quite good, but there is a conflict left. Perhaps it was based on an older branch? Could you resolve that one?

Here you can see the resulting diff from the MR: https://git.drupalcode.org/project/views_infinite_scroll/-/merge_request...
In the end it should be equal to your one?

himanshu_jhaloya’s picture

I was facing the same issue but checked with views_infinite_scroll-2852080-2852080-different-item-count this branch it is working fine for me thanks @christiansanders

anybody’s picture

Thanks. So the last step here seems to be to add test coverage?

rsych’s picture

I checked the patch from #61, and there is another bug. My steps:
1. I set 6 items to show on load
2. I set 3 items to add on each "load more" click (I use the button)
Result: when I have 3 items in total, no "load more" button is shown (correct). But after creating another node, I have this behavior: it shows 4 nodes and (here's the error itself) the "load more" button. After clicking on this button, it disappears (without adding any item because everything is already displayed).

ypx’s picture

StatusFileSize
new5.6 KB

This is an updated patch file to fix the bug reported at #68
The number of pages needs to be recalculated
When creating a pager we set total items = current_total_items + (items_per_page - initial_items).

damienmckenna made their first commit to this issue’s fork.

damienmckenna’s picture

Status: Needs work » Needs review

I updated the merge request with the changes from #69 (and the latest changes from the 2.0.x branch).

In my local testing the new options work well, thank you all.

anybody’s picture

Thanks, still needs tests (FunctionalJavascript) as last step, right? Who's our hero? 🦸🦸‍♀️

anneke_vde made their first commit to this issue’s fork.

anneke_vde’s picture

I added a test for the different initial loading and after first page loading other amount.

mugesh.s made their first commit to this issue’s fork.

mugesh.s’s picture

Assigned: Unassigned » mugesh.s
StatusFileSize
new9.85 KB

Alternative Implementation

Hi @all,

This approach provides another way to implement the feature without disturbing the current functionality.
Please review, test, and confirm if this works as expected.

I’ve also added test coverage to validate the behavior.

Issue Summary

This proposal adds a new “Page Control” feature to the Views Infinite Scroll pager plugin, allowing site builders to specify different item counts for:

  • The first page
  • All subsequent pages

This is useful in UX scenarios where the first page of a listing (e.g., landing pages or featured sections) should show fewer or more items than the rest.

Proposed resolution

  • ntroduce a checkbox Enable Page Control in the pager settings.
  • When enabled:
    • Hide the existing Items per page field.
    • Show two new number fields:
      • Items for the first page
      • Items for the other pages
  • Modify internal pagination logic to:
    • Set per-page limits conditionally based on current page.
    • Adjust offset and total count logic accordingly.
  • Update getRemainingItems() and getNumberItemsLeft() methods to reflect accurate counts.
  • include #states logic in the options form for dynamic field visibility.

User interface changes

A new checkbox and two conditional number fields will be shown in the Views UI under the pager settings.

Example Use Case

For example, I want to display only 4 items on the homepage (page 0), but load 2 items on all other pages. This feature enables that flexibility without needing to override views programmatically.

Video Demonstration

Here’s a working demo of the feature implemented on my site:

View page control  settings demo


View page control output demo

This feature has been implemented in the branch:
2852080-Add-Page-Control

A patch has also been attached here for testing.

✅ Please review and test the patch and merge request.
💬 Feedback and suggestions are most welcome!

mugesh.s’s picture

StatusFileSize
new10.69 KB

Use Add-Page-Control-2852080-#78.patch this patch to avoid warning errors.

weareronin’s picture

Successfully tested patch #78 in our project. Thanks !

herved made their first commit to this issue’s fork.

herved’s picture

Rebased the MR and added a few changes/fixes on top:

  • Coding standards fixes and return types.
  • Removed the unsupported default: key from the config schema.
  • Replaced the positive-integer validator with a number element.
  • Fixed the button tokens: they assumed every page holds items_per_page items, so with initial=2, items_per_page=4 and 11 results the button read "Load 4 of 7 remaining" on the first page (9 remain) and still "Load 4" when 1 remained.
  • query() no longer overrides the parent unconditionally: views not using the feature keep core behavior (the total_pages clamp was lost, and items_per_page=0 showed only initial items with no way to load the rest).
  • Test coverage for all of the above.