如何使用ACF将其创建为Wordpress短代码

问题描述 投票:0回答:1

我使用的大多数字段都来自ACF专业插件,其中一些使用的是ACF的中继器,我的PHP不好,如何将下面的代码转换为简码?

<div class="row">

    <?php 
        if( have_rows('our_golf_tours_list',161) ):                   
    ?>            
    <?php 
         while( have_rows('our_golf_tours_list',161) ): the_row();                   
    ?>

        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-3 m-b-30 col-package">
        <div class="packages-box">
            <a href="<?php the_sub_field('title_link'); ?>"><img src="<?php the_sub_field('image'); ?>" alt="img"></a>
            <div class="package-details-2">
                <h3><a href="<?php the_sub_field('title_link'); ?>"><?php the_sub_field('title'); ?></a></h3>
                <p><?php the_sub_field('date'); ?></p>
            </div>
        </div>
        <div class="packages-box-bottom">
            <a href="<?php the_sub_field('book_now_url'); ?>" class="btn btn-default-custom book-now-small <?php the_sub_field('hubspot_class'); ?>">Book Now <i class="fa fa-angle-right" aria-hidden="true"></i></a>
            <a href="<?php the_sub_field('itinearay_url'); ?>" class="btn itinerary-blank">Itinerary </a>
        </div>
    </div>

    <?php endwhile; ?>

    <?php endif; ?>
</div>

下面的这段代码是否正确?如果我错了,请纠正我。

function repeater_ad () { 

echo '<div class="row">

    <?php 
        if( have_rows('our_golf_tours_list',161) ):                   
    ?>            
    <?php 
         while( have_rows('our_golf_tours_list',161) ): the_row();                   
    ?>

        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-3 m-b-30 col-package">
        <div class="packages-box">
            <a href="<?php the_sub_field('title_link'); ?>"><img src="<?php the_sub_field('image'); ?>" alt="img"></a>
            <div class="package-details-2">
                <h3><a href="<?php the_sub_field('title_link'); ?>"><?php the_sub_field('title'); ?></a></h3>
                <p><?php the_sub_field('date'); ?></p>
            </div>
        </div>
        <div class="packages-box-bottom">
            <a href="<?php the_sub_field('book_now_url'); ?>" class="btn btn-default-custom book-now-small <?php the_sub_field('hubspot_class'); ?>">Book Now <i class="fa fa-angle-right" aria-hidden="true"></i></a>
            <a href="<?php the_sub_field('itinearay_url'); ?>" class="btn itinerary-blank">Itinerary </a>
        </div>
    </div>

    <?php endwhile; ?>

    <?php endif; ?>
</div>';
add_shortcode('sss', 'repeater_ad');    
wordpress advanced-custom-fields shortcode
1个回答
1
投票

您的简码有一些问题:

© www.soinside.com 2019 - 2024. All rights reserved.