I have a website that works with Drupal 10.2.5

I have 200 articles published.

I created a views block with the last 5 articles. I therefore limit the number of elements to 5.

I want to display in the header of my views the total number of articles, which is 200.

Here is my problem:

This does not work because the views only counts the number of elements displayed 5. How to calculate the total number of elements?

I tested all the available tokens and none are capable of doing this.

Can you add a token in Drupal to do this?

Comments

zenimagine created an issue. See original summary.

aaron.ferris’s picture

Hello @zenimagine

Are you using the view header via the UI?

  1. Header - add
  2. For the 'Search' input type 'Result summary'
  3. Check 'Result summary' and click "Add and configure header"
  4. Add required text, the token you're looking for (I believe) is @total
zenimagine’s picture

This is precisely the problem, because the Views only counts visible elements. If I have 200 elements and I limit the display to 5, the Views displays 5 in the results. I want to display a number of 200

aaron.ferris’s picture

Ignore me, I follow, so we'd want the total item count above and beyond the configured item count.

Couldn't you configure this to have a paged output, with 5 items per page, then hide the pager? Feels a bit crude and id imagine someone else may have a better idea but this will probably need some sort of preprocess id imagine.

aaron.ferris’s picture

johnv’s picture

Title: How do I display the total number of items in a view ? » How to display the total number of items in a view?
Component: views.module » views_ui.module
Category: Feature request » Support request

In D11 (and before?) you can add a 'Global: Result summary' to the header or the footer.
By default it displays "Displaying 1 - 31 of 31".

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Active » Fixed

There are several solutions offered here, and no ongoing discussion.

I am closing this per the guidance in Handle or refer a support request in an issue.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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