I am displaying a multi-instance image custom field using wpv-for-each.
I only render the first couple of images (e.g. first 3) and then I want to display a link with "+[NUMBER OF IMAGES]" remaining.
[wpv-for-each field="wpcf-images" start="4"]
+[NUMBER OF IMAGES]
[/wpv-for-each]
I would like to know how I may display the "+[NUMBER OF IMAGES]".
Is there a direct attribute to do that or how may I do it?
Thanks
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Andrei
I'm not sure what you intend to link to.
You can register a shortcode which will display how many instances of the field there are for example, or a shortcode to display the current instance as an index, so that you could display something like "2 of 6", for example.
Here are shortcodes that would do those:
add_shortcode('wpv-instances', function ($atts = []) {
// provide defaults
$atts = shortcode_atts(
array(
'field' => '',
),
$atts
);
if ( isset( $atts['field'] ) ){
global $post;
$values = get_post_meta( $post->ID, $atts['field'], false );
$count = count( $values );
return $count;
}
});
add_shortcode('wpv-index', function () {
static $i = 1;
$n = $i++;
return $n;
});
You when use them inside a wpv-for-each loop like so:
[wpv-for-each field='wpcf-telefono']
<p>[types field='telefono'][/types] ([wpv-index] of [wpv-instances field='wpcf-telefono'])</p>
[/wpv-for-each]
But I don't really understand the request about linking to something.
My issue is resolved now. Thank you!