Skip Navigation

[Resolved] how to generate incremental value in view

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

Our next available supporter will start replying to tickets in about 0.33 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 18 replies, has 2 voices.

Last updated by Beda 6 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#952118

i cross 1 hurdle and 2nd is there.

i have used tabs inside my view. (Loop)
as the unique identity is not there in side loop its not functioning properly .

I need a way to pass a unique value for the tabs inside loop
e.g
tab1 , tab2 , tab 3

can u please tell how can i use

x=0
x=x+1

tab[x]
some thing like this ?

thanks in advance

#952482

16 hours and no replay . can my tickets be replied on time.

#952484

i am trying to do some thing like this
<button class="tablinksimg " onclick="openTabimg(event, '1stStory[incrementor]')">1st Story</button>

&
<div id="1stStory[incrementor]" class="tabcontentimg" >

but its not working . i need unique ids . please guide how is that possible.
thanks
yes i have set up a shortcode in function.php

#952774

I apologize the unusually slow reply time, there is a higher amount of support requests and today I'll see what I can handle.

Let me reply to the issue:

1. There is no such feature as asked for here:
https://toolset.com/forums/topic/how-to-generate-incremental-value-in-view/#post-952118

However it's as well not necessary for your goal
Simply use the Toolset ShortCode for the Post ID, for example.
When you populate your Tab's HTML ID with that ShortCode, it'll be unique for each post looped.
You can construct more complex ID's by putting together other ShortCodes.

If you need a real increment counter, you can either create a Custom ShortCode, or see if the Toolset View's Loop item/index can help you with this, this is a ShortCode to address specific items in a loop:
https://toolset.com/documentation/user-guides/digging-into-view-outputs/#vmeta-wpv-loop-parameters
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-154400
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153482

2. https://toolset.com/forums/topic/how-to-generate-incremental-value-in-view/#post-952484

I am not sure what ShortCode you have setup, you do not need one for this task, I think you can simply use the ShortCode as above explained.

<button class="tablinksimg " onclick="openTabimg(event, '1stStory[wpv-post-id]')">1st Story</button>

&
<div id="1stStory[wpv-post-id]" class="tabcontentimg" >

Let me know if that helps

#952776

Dear Beda,
thank you very much for replying.

using any value from same post will remain same through the loop

my point is to make the value unique inside loop and that is only possible if the value keep changing on ever loop cycle
I tried using custom function like i mentioned above

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

i am trying to do some thing like this
<button class="tablinksimg " onclick="openTabimg(event, '1stStory[incrementor]')">1st Story</button>

this part dont work and i get out put as

<button class="tablinksimg " onclick="openTabimg(event, '1stStory[incrementor]')">1st Story</button>

&
<div id="1stStory[incrementor]" class="tabcontentimg" >

this part works and out is as

<div id="1stStory14" class="tabcontentimg" style="display: none;">.... </div>

i need to know what wrong i am where its not converting shortcode value

thanks in advance,
a quick response is appreciated

#952780

"using any value from same post will remain same through the loop"

You do not, as outlined, use the same value from the same post, but you are in a View, in a Loop, you loop over several posts, hence, that will be unique.
No post ID is the same always.

Toolset Views offers no autoincrementing ShortCodes.
You can target single items or listen if an item is of a certain index in the loop:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-154400
You can do things for each item in a loop:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each

But you cannot auto-count incrementally like you show.
For that usually we use Post ID; as the Post ID is the unique element here.

For example a List of Links with their respective Bootstrap Modals popping up can be created exactly like that using the Post ID as a ID attribute in a Views Loop.

Your ShortCode BTW does the exact what it should:
It outputs an incrementing number starting at 1.
I tested it in a view that lists posts.

#952788

Dear beda,
""using any value from same post will remain same through the loop""

are you trying to tell me that view can only be used for multiple posts and i am doing wrong using it for single post ?

"Toolset Views offers no autoincrementing ShortCodes."
are you tyring to tell me this plugin is a bad choice and i should cancel the subscription ?

"But you cannot auto-count incrementally like you show."
ok tell me

I got n number of tabs in a loop
do let me know how to create unique records ( keep in mind i am creating a view to display single post. here is the link to the page
hidden link

the tabs you see
1st story
2nd story
then
interior inspiration
Facade options
these will be generated in loop automatically for each tab ( alaska 15 to n~)
alaska 15
alaska 17 are linked with the parent post Alaska
and they can go to n number

I am on single page loop. so every values in coming from same post . or its connected posts .

what is having issue is

<button class="tablinksimg " onclick="openTabimg(event, '1stStory[incrementor]')">1st Story</button>

this part does not work and i get out put as

<button class="tablinksimg " onclick="openTabimg(event, '1stStory[incrementor]')">1st Story</button>

&
<div id="1stStory[incrementor]" class="tabcontentimg" >

this part works and out is as

<div id="1stStory14" class="tabcontentimg" style="display: none;">.... </div>

i need to know what wrong i am where its not converting shortcode value

thanks in advance,
a quick response is appreciated

#952790

"are you trying to tell me that view can only be used for multiple posts and i am doing wrong using it for single post ?"

It is not wrong, but it is the main purpose of a Loop, to produce several results.
A view, usually is used for display many posts, as if you want to display just one post, you can use either the post itself, or a Content Template for example.

However, in a Single Post, there is no Loop, there is no auto-incremental triggering at all.

"are you tyring to tell me this plugin is a bad choice and i should cancel the subscription ?"

If your only requirement from Toolset is a feature that counts incrementally a number in a single Post upon some (unknown) values, then yes, I am sorry the Toolset does not offer this kind of feature and cannot, as there is no way without a loop to produce an incrementing value, and within the Toolset Views Loop we have no such specific ShortCode, as it is usually possible to replace with the Post ID or other unique values, or, as you show, with the simple Custom ShortCode, which works great in a Views loop.

"I got n number of tabs in a loop
do let me know how to create unique records ( keep in mind i am creating a view to display single post. here is the link to the page"

As said, this is not possible.
Try to achieve the same with PHP, you would see that this is not possible from it's logic.

1. To loop, you need several items
2. With several items you can loop and repeat things or add unique things to the single items in the loop

So, to generate a HTML that adds as many "items" of something (tabs, buttons, links, whatever it may be) we need many items to produce (for each) such an element.
In the View you have now, there is only one element, hence there will be only one output tab, for example.

What you would need to do is loop over the Items that should defined how many tabs there are (and in Views, this can be Posts, Users or Taxonomy Terms)
Then, you add the HTML that for each such item (Post, user or term) produces the HTML you want.
That then is populated with each pots, users or taxonomy single data (like title, or so)

Each tab (or any other HTML you added in the loop) will then be made for/by each single post looped in there.

Does that clear up things?

On a Single post, you cannot do that, as there is no loop that returns many things.
(Unless, as above shown you use a View of posts or users or taxonomies...)

Please let me know if there are unclarities left.

#952791

very disappointed by the reply of beda need some expert to look over and provide a solution

#952792

i am not provided with any solution

all i am being told is its a bad choice that i was working with toolset

all beda can do is reply ingeneric without even looking at the url i posted
there must be a small syntax issue as my code is working at other place and not at 1st place

#952799

I am sorry, Burt you asked, me, if Toolset can do this.
It can not do this.

It can however help you to do this this, and with a ShortCode like you created it can be done.
This, in a Loop.

If you require this on a Loop that has just one post, Toolset cannot increment something - even the ShortCode you created (which works in a "normal" view) would not work.

So, I have no other choice but to say that if (according your questions) this is the one and only thing that makes the difference of keeping toolset or not, then I cannot tell you to keep it - its not possible. And it seems it's what you want.
Toolset cannot do this, PHP cannot do this.

Not in a loop, where you hav just one thing to act upon which is the case both in a view that returns one result or in a single post.

I tried to explain to you in detail how this is thought.
You did not reply to any of those points, but expect me to look at the page.
I did.
I saw what I saw, combined it with what you described and it made sense, it is one item, and there can be no increment or other kind of looped repeating / adding event.

>there must be a small syntax issue as my code is working at other place and not at 1st place

Then let me know about those working locations.
I may be able to tell you why it is working at one spot but not another.

However - it seems to me that you want some code (to auto increment a value) to run, and increment, a value, for as many times, as there are items of a certain kind.

And that, is done in a Loop, where you loop over those items
Those items, in Views, can be only users, Taxonomies or posts.
In a post view, you can for example display the posts fields and data in such structures, if you output more than just one item (otherwise, you have n nothing to increment).

This is not something I invented, and I will not further discuss this here.

I can of course add a feature request.

Could you describe how such a feature should work and where, so I can ask the developers to do it?
Maybe they find a way to make it possible

#952824

i am pasting image here to proof BEDA is not reading any of my queries and is replying just for the sake of point scoring or what every
his latest query is
">there must be a small syntax issue as my code is working at other place and not at 1st place
-----------------------------------------------------------------------------------
Then let me know about those working locations."

hidden link
-----------------------------------------------------------------------------------
my complete explanation is
1st
hidden link
2nd
hidden link

writing stories in email i can do that too i can write 100's of lines in reply
but some 1 needto check this guy why is he inquiring same info again and again

#952834

Well, that is no new information and not any detail that describes the issue.

You say, you need to auto increment something to make those ID's count and I described what is possible, how to and where.

If you feel I do not get it, feel free to wait for a Supporter next week.
I have no other idea.

If you refer to something that breaks the syntax of HTML, then I do not understand the point about
<blcokquote>
I need a way to pass a unique value for the tabs inside loop
e.g
tab1 , tab2 , tab 3

can u please tell how can i use

x=0
x=x+1

tab[x]
some thing like this ?

thanks in advance

This, has nothing to do with what you post in your screenshot.

Your ShortCode DOES WORK if you put it in a Loop that can feed it.
Test it, in a View, that gives you more than one post.
[incrementor], with the code you suggested, will output a increasing count of numbers 1 2 3 4 one each iteration and that is how things work with Toolset and loops.

I a single output that cannot work.

If you rewire further assistance, use this form to complain about me:
https://toolset.com/?page_id=421149

Thank you.

#952845

BTW, re reading this thread for many times I see one last possible thing you may be failing on:

https://toolset.com/forums/topic/how-to-generate-incremental-value-in-view/#post-952776

You use the shortcode once in a html Attribute and once in a JS function?

ShortCodes can, according WordPress, not be used to populate html attributes, nest them, or add to JS.
Now, Toolset makes some of it possible, but it doesn’t allow ShortCodes in JS functions either.

I’m not sure where the exact code is inserted but if it’s expecting the shortcode to return a value in a JS then that cannot work.

ShorCodes only work When expanded with the html section.

Remember also, when you use your shortcode, to register your custom shortcode in Toolset menu “settings > custom content” (in case you want to use it in nested ShortCodes or maybe conditionals)
However - registering it will still not execute it elsewhere but in html

This does as well not resolve the issue where if you want to let something “loop” (several times the same code, increment) you would need more than one result to work on

Maybe the last input helps
I don’t know any further scenarios

#952849

the problem is not resolved. beda is not ready to help