Saltar navegación

[A la espera de la opinión de los usuarios] showing X to Y of Z Records in views

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Este tema contiene 3 replies, tiene 1 mensaje.

Última actualización por - 3 days, 11 hours ago.

Asistido por: Christopher Amirian.

Author
Mensajes
#2891335

In a view, I would like to have toolset display: "1-10 of 100 records" on the first page of results and then "11-20 of 100 records" on the next page etc etc ...

"[wpv-items-count] of [wpv-found-count] Items" will always display "10 of 100 Items" so how do I display the start - stop count for each specific page of results returned?

thx

#2891776

Christopher Amirian
Colaborador

Idiomas: Inglés (English )

Hi,

Welcome to Toolset support. There is no built-in shortcode for the per-page range. [wpv-items-count] returns the number of items on the current page, and [wpv-found-count] the total before pagination, so you need the first/last index calculated from the View’s query.

Add this to your child theme’s functions.php or to a new snippet in Toolset → Settings → Custom Code:

/**
 * [wpv-items-range] - outputs "11 - 20" for the current page of a View loop.
 */
add_shortcode( 'wpv-items-range', function( $atts ) {
	$atts = shortcode_atts( array( 'separator' => ' - ' ), $atts );

	$query = apply_filters( 'wpv_filter_wpv_get_post_query', null );
	if ( ! $query instanceof WP_Query || 0 === (int) $query->post_count ) {
		return '';
	}

	$per_page = (int) $query->get( 'posts_per_page' );
	$paged    = max( 1, (int) $query->get( 'paged' ) );

	if ( $per_page < 1 ) {
		$per_page = (int) $query->post_count;
		$paged    = 1;
	}

	$first = ( ( $paged - 1 ) * $per_page ) + 1;
	$last  = $first + (int) $query->post_count - 1;

	return $first . $atts['separator'] . $last;
} );

Then in the View’s loop output:

Showing [wpv-items-range] of [wpv-found-count] records.

Notes:

- Place the shortcode inside [wpv-items-found], outside <wpv-loop>.
- Separator is optional: [wpv-items-range separator=" to "].
- This covers post queries. For a View querying users or taxonomy terms, the counts come from wpv_filter_wpv_get_user_query / wpv_filter_wpv_get_taxonomy_query instead.

For more information:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/

The custom code suggested above is not part of our official support policy. We will not be able to maintain or guarantee that it will work. It is an attempt to help you understand what should be done for scenarios where the built-in Toolset features are not there to handle your request.

Thanks.

#2896536
Screenshot 2026-11-05 at 11.35.22 AM.png

ok. So I added the Snippet but when I click on "Save and Test" or "Save and Close" I get the message (error)

#2907791

Christopher Amirian
Colaborador

That message is generic. It appears whenever the save request fails, without saying why, so we need to find the real reason.

Three things to check, quickest first.

1. Copy the code again. If the forum's line numbers came along with it, the file is invalid PHP and the save will fail. The code should start with `/**` and there should be no digits at the start of the lines.

2. Open `wp-config.php` and look for these:

```
define( 'DISALLOW_FILE_EDIT', true );
define( 'DISALLOW_FILE_MODS', true );
```

If either is there and set to true, Toolset cannot write snippets. Many hosts add them.

3. Check that `wp-content/toolset-customizations/` exists and is writable by the web server. Toolset stores each snippet as a real PHP file there.

If all three look fine, please send me the server's answer: open the browser console on the Custom Code screen, go to the Network tab, click Save again, and copy the response of the failing request. Also check `wp-content/debug.log` if you have `WP_DEBUG_LOG` on.

In the meantime you can put the same code in your child theme's `functions.php`. It works the same way and skips this screen entirely.