1

我有 php 代码(ACF Pro 插件代码)。如何将此代码插入到我的 Visual Composer 中?很长一段时间都找不到解决方案,但现在这对我来说很重要。

<?php if( have_rows('add_a_new_table') ): ?>
    <?php 
    while( have_rows('add_a_new_table') ): 
        the_row(); 
        // vars
        $t_title         = get_sub_field('t_title');
        $t_pricing       = get_sub_field('t_pricing');
        $t_emails_number = get_sub_field('t_emails_number');
    ?>       
        <div class="col-sm-12 col-sm-4 text-center">
            <div class="courses-column">      
                <div class="courses-column-inner">
                    <h3><?php echo $t_title; ?></h3>
                    <p style="font-size: 24px;">
                        <?php echo $t_pricing; ?>
                    </p>
                    <br>
                    <p style="font-size: 16px;">
                        <?php echo $t_emails_number; ?>    
                    </p>
                </div>
            </div>
        </div>

    <?php endwhile; ?>
<?php endif; ?> 

由于 if 和 while 条件,我无法通过简码实现它。Row HTML 和 Row JS 对我来说也没用。

4

2 回答 2

14

只需将您的 php 代码放在一个函数中并创建短代码

function vComp(){
**PHP CODE**
 }
add_shortcode( 'vShortcode', 'vComp' );

转到 Visual Composer- Shortcode Mapper - Map Shortcode - 然后输入有效的简码(例如:[vShortcode])。

于 2016-11-16T07:29:00.957 回答
3

在 functions.php 页面中创建函数。

function shortcode (){
}
add_shortcode('shortcode-name',shortcode );
于 2017-06-12T04:15:12.200 回答