Insert PHP code into the Visual Composer

五迷三道 提交于 2019-12-19 04:43:06

问题


I have the php code (ACF Pro plugin code). How can I insert this code into my Visual Composer? Can't find the solution for a long time but now it's critical for me.

<?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; ?> 

I can't realize it via shortcodes because of if & while conditions. Row HTML and Row JS are useless for me as well.


回答1:


Just put your php code inside a function and create shortcode

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

Goto Visual Composer- Shortcode Mapper - Map Shortcode - then Enter valid shortcode (Example: [vShortcode]).




回答2:


Create function in functions.php page .

function shortcode (){
}
add_shortcode('shortcode-name',shortcode );


来源:https://stackoverflow.com/questions/40626217/insert-php-code-into-the-visual-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!