Skip Navigation

[Resolved] Simple row numbers in views

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Tagged: 

This topic contains 5 replies, has 3 voices.

Last updated by jonS-2 7 years, 6 months ago.

Assisted by: Konstantinos Galanakis.

Author
Posts
#446344

I am trying to: Display row numbers for found items in any view

I've built the custom function described by Caridad in her response: https://toolset.com/forums/topic/incremental-row-numbers-in-views/#post-31061

Those work fine, however, if I have more than one view on a page, the numbering just continues to climb. I've tried to reset the counter, but it doesn't seem to work.

Is it really that difficult to add an incrementing variable to Views that could be used to display the current item index? That would help us all solve so many things without having

#446543

Hello Anthony.

Thank you for contacting the Toolset Support.

Could you please elaborate a little more on what you need to achieve so I can better understand?

Sometimes screenshots illustrating what you mean may go a long way to clarify what words fail to transmit, so if you like, make use of "upload an image" below the comment area.

My first thought on this is that you can use an ordered list inside your loop in each view you are including on your page. You can find all the relevant information regarding ordered lists here https://toolset.com/documentation/user-guides/view-layouts-101/#ordered

Looking forward to hearing from you soon.

If you have any further issues, please let me know.

Regards

#446732

Ordered list is a great solution to my immediate problem, but I still think there should be an available variable in every view for the number of the item that the loop is currently processing. Something like [index]

So, within my view loop:
[wpv-found-items] I can simply insert a shortcode like [index] that the Views plugin will replace with the current iteration number of the loop.

This value is important because it would be VERY useful for conditionals:

[wpv-found-items]
[wpv-if [index] > 10 ] found items # 11 and above. [wpv-if]
[wpf-if [index] \ 2 ] all even numbered items [wpv-if]
[wpf-if [index] \ 6 ] every 6th item [wpv-if]
[/wpv-found-items]

#446741

Hello Patrick.

In that case, you might want to try the code below that seems to perform as needed

add_shortcode('incrementor', 'incrementor');
function incrementor() {
    global $WP_Views;
    static $current_view = -1;
    static $i = 1;
    if($current_view != $WP_Views->current_view)
    {
        $i = 1;
        $current_view = $WP_Views->current_view;
    }
    return $i ++;
}

and use the [incrementor] shortcode where needed.

If this doesn't resolve your issue or you have any further issues or questions, please let me know.

Regards

#446758

Excellent! I had been using some code from another post, but it failed to account for multiple views on a single page.

The overall problem with WP-Views is that it needs custom code far too often. Although your code is perfect for my situation, this website now has custom functions, rather than having all of the logic contained in the view itself.

WP-Types needs to work on adding this function to the core Views interface where it can be used without touching functions.php. It would help make your company grow!

Thanks again!

#526046

I second this. I think it would be a simple addition to the long list of shortcode pre-built into tools. I found it difficult to understand that there isn't a shortcode inside toolset that will show this already considering the applications.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.