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?
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>
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 ...)