Skip Navigation

[Resolved] Display item-number 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.

This topic contains 2 replies, has 2 voices.

Last updated by dianaM-4 4 years, 8 months ago.

Assigned support staff: Minesh.

Author
Posts
#484142

Hi all!
I'm wondering, if there is a quick way to display the index-number of an item in a list-view. Just like:

<!-- wpv-loop-start -->
<wpv-loop>
    <div id="block-[wpv-item-indexnumber]">
        This is my [wpv-item-indexnumber]. post.
     </div>
</wpv-loop>
<!-- wpv-loop-end -->

Is there an API or a shortcode for that?

#484259

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

No there is no such shortcode available with Toolset. You may try to use [wpv-item] shortcode with "index" attribute:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-item

For example:

<wpv-loop>
    [wpv-item index=1]
      your output 
    [wpv-item index=2]
      your output
    [wpv-item index=other]
      your output
 </wpv-loop>

More info:
https://toolset.com/documentation/user-guides/digging-into-view-outputs/
[Section: "Loop parameters & wpv-item : wrap, pad, pad-last, index"]

Or

Add these lines to functions.php in your theme folder:

add_shortcode('incrementor', 'incrementor');
function incrementor() {
static $i = 1;
return $i ++;
}

Then define your View template as:

<wpv-loop>
<li class="block-[incrementor]"> 
your content
</li>
</wpv-loop>

But - if your need is to make ids unique then you can use [wpv-post-id]. For example

<wpv-loop>
<li class="block-[wpv-post-id]"> 
your content
</li>
</wpv-loop>
#484629

Thanks Minesh,
that helped a lot! I used your php-shortcode and it works perfectly!
Best regards, Diana

(I needed a fixed ID, that stays the same on all translated pages. So in this case the post-ID or post-slugs didn't work for me ...)