将 PHP 代码插入 Visual Composer

Posted

技术标签:

【中文标题】将 PHP 代码插入 Visual Composer【英文标题】:Insert PHP code into the Visual Composer 【发布时间】:2017-03-30 07:15:15 【问题描述】:

我有 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 对我来说也没用。

【问题讨论】:

wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332 【参考方案1】:

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

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

转到 Visual Composer- 简码映射器 - 映射简码 - 然后输入有效的简码(例如:[vShortcode])。

【讨论】:

非常感谢! @Morgari 谢谢【参考方案2】:

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

function shortcode ()

add_shortcode('shortcode-name',shortcode );

【讨论】:

以上是关于将 PHP 代码插入 Visual Composer的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Microsoft Visual Studio 将查询插入到 C# 中的另一个查询中?

使用Visual Studio扩展插件Visual assist X给代码插入注释模板

使用Visual Studio扩展插件Visual assist X给代码插入注释模板

使用docker-compose和https时如何让Visual Studio启动正确的URL

如何使用 Visual C++ 的内联汇编器插入重复的 NOP 语句?

visual2019怎样插入标签插入标签