Skip Navigation

[Resolved] Display item-number in views

This support ticket is created 7 years, 2 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by dianaM-4 7 years, 2 months ago.

Assisted by: 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 ++;
}
[php]
Then define your View template as:
[php]
<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 ...)

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