Skip Navigation

[Closed] View the exact amount of uploaded pictures

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

This topic contains 3 replies, has 2 voices.

Last updated by Waqas 7 years, 1 month ago.

Assigned support staff: Waqas.

Author
Posts
#322809

I am trying to: Display the exact amount of uploaded pictures

In my CPT I add a Costum Post Field to upload pictures:
hidden link

In my View I like to display exactly the amount of pictures which are uploaded - for example if somebody uploaded 7 pics I like to display 7 pics. I can not handle it in the moment - the code in my content template looks like this:

(Its a shortcode in a shortcode - i insert the type fields into a shortcode-slider of my theme provider):
--------------------------------

[ux_slider]

[ux_banner bg="[types field="yogareise-foto" index="0" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="1" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="2" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="3" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="4" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="5" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="6" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="7" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="8" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[ux_banner bg="[types field="yogareise-foto" index="9" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[/ux_slider]

---------------------------

So now it looks like this: hidden link
A slider with 10 pictures uploaded - 7 pics / 3 empty

Can you point me in the right direction how to display a costum post field into a slider if there a multiple instances and I dont know the exact amount of pic that will be uploaded?

Thanx so much for your support!!
Petra

#322818

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Unfortunately, there's no such short code available. But you can create a custom short code for this purpose. Please consider following code:

add_shortcode( 'count-repeats', 'count_repeat_func' );
function count_repeat_func($atts) {
    return sizeof(get_post_meta( get_the_ID(), 'wpcf-' . $atts['field'], false ));
}

Add this code to your theme's functions.php file and use as below:

[count-repeats field="photos"]
#323276

Thanx for your support! And great you point me in the right direction to fix it. I added the shortcode to my theme`s function.php but i am not sure where to add this code:
[count-repeats field="photos"]

I put it in the index="" (before it was index="0", index="1", index="2") but I guess this was wrong:

-----
[ux_slider]

[ux_banner bg="[types field="yogareise-foto" index="[count-repeats field="photos"]" output="raw"][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

[/ux_slider]
----

Can you just help me out where to insert the shortcode? Thanx a lot!!

#323290

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

There are 3 things to consider, please see followings:

1) The short code [count-repeats field="photos"] must be within the loop. Like if you are generating slides in a View, then it must be within <wpv-loop> tags. It doesn't matter if you use it as an attribute to another short code or HTML tag.

2) When using short code as an attribute to another short code or HTML tag, you must use alternate quotes, for example:

[ux_banner bg="[types field='yogareise-foto' output='raw'][/types]" height="450px" text_align="center" text_pos="center" text_color="light" text_width="80%"]
[/ux_banner]

Please notice the single quotes used for [types] short code attributes, while short code itself is surrounded by the double quotes.

3) Remember to register [count-repeats] short code in Views -> Settings -> Compatibility -> Third-party shortcode arguments. This is necessary to make this short code to run in the View. I am sorry I forgot to mention this earlier.

Finally, since this short code returns the number of items in a repeater field. It should be used at appropriate place. It will return number of items. While you have used it as an index to the repeating field. Which means the [types] short code will return results at that particular index, which will never be reached in this case.

Please see https://toolset.com/documentation/customizing-sites-using-php/functions/#image for more information. Click the '+More' icon to reveal details in 'index' attribute of this field.

The topic ‘[Closed] View the exact amount of uploaded pictures’ is closed to new replies.