Skip Navigation

[Gelöst] Embed flexslider Code

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: Can I embed Toolset wpv-for-each shortcodes in my PHP templates to loop over repeating fields?

Solution: No, you should use the native WordPress function get_post_meta to get the values of your repeating field, then loop over those values and output the proper HTML strings. This is not a trivial task. Here's a simple example of looping over a repeating image field in PHP:

$string = '';
$medias = get_post_meta(12345, 'wpcf-wpcf-medias', false);
foreach($medias as $img) {
  $string .= "<a href='" . $img . "'><img src='" . $img . "' /></a>";
}
echo $string;

Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta/

This support ticket is created vor 6 Jahre, 1 Monat. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 Antwort, has 2 Stimmen.

Last updated by Christian Cox vor 6 Jahre, 1 Monat.

Assisted by: Christian Cox.

Author
Artikel
#628265

Hi,

I'm using Flexslider for my portfolio, so everything it's working perfectly but the problem is when all post fields are generated they are all of them inside the tag <article></article> and I would like to isolate my portfolio. So I would like to know if it's possible to embed my Portfolio template code directly on my page "single-portfolio.php"?

I have tried to embed this code but it doesn't work :

<div class="flexslider">

<ul class="slides">
[wpv-for-each field="wpcf-wpcf-medias"]

  • <a href="[types field='wpcf-medias' alt='%%ALT%%' title='%%TITLE%%' size='large' align='none' resize='proportional' separator=', '][/types]" classe="img-box img-scale-rotate lightbox">[types field='wpcf-medias' alt='%%ALT%%' title='%%TITLE%%' size='large' align='none' resize='proportional' separator=', '][/types]</a>
  • [/wpv-for-each]

    </div>

    Thank for you help

    #628451

    Hi, Types shortcodes are not meant to be used directly in PHP, they are meant to be used in wp-admin. Instead, you should use the native WordPress function get_post_meta to get the values of your repeating field, then loop over those values and output the proper HTML strings. This is not a trivial task. Here's a simple example of looping over a repeating image field in PHP:

    $string = '';
    $medias = get_post_meta(12345, 'wpcf-wpcf-medias', false);
    foreach($medias as $img) {
      $string .= "<a href='" . $img . "'><img src='" . $img . "' /></a>";
    }
    echo $string;
    

    Here's the documentation for the get_post_meta function:
    https://developer.wordpress.org/reference/functions/get_post_meta/

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