【问题标题】:Visual composer custom loop shortcode视觉作曲家自定义循环简码
【发布时间】:2019-09-03 07:06:13
【问题描述】:

我需要使用来自可视化作曲家的自定义循环:

if( function_exists('vc_map') ) {

    vc_map( array(
        'base' => 'minimag_popular_post_custom',
        'name' => esc_html__( 'Popular Post Custom', "minimag-toolkit" ),
        'class' => '',
        "category" => esc_html__("Minimag Theme", "minimag-toolkit"),
        'params' => array(
            array(
                // this param
                "type" => "loop",
                "heading" => esc_html__("Display Custom Loop", "minimag-toolkit"),
                "param_name" => "custom_loop",
            )
        ),
    ) );
}

过去我使用过 vc_link,它具有正确的函数来以正确的形式检索值:vc_build_link($href)

有一些函数可以从循环参数中提取数据吗?我查看了参考资料,但什么也没找到。

这是我需要解析的输出示例:

size:8|order_by:date|order:DESC|post_type:post|categories:32,5|by_id:1537,1673

我需要类似的东西:

$myVar['size'] = 8;
$myVar['order_by'] = 'date';
$myVar['order'] = 'DESC';
$myVar['post_type'] = 'post';
$myVar['categories'] = array(32,5);
$myVar['by_id'] = array(1537,1673);

【问题讨论】:

    标签: wordpress visual-composer wpbakery


    【解决方案1】:

    测试和工作:)

    list($args, $wp_query) = vc_build_loop_query($atts["custom_loop"]);
    
    while ( $wp_query->have_posts() ) {
       $wp_query->the_post();
    }
    
    wp_reset_postdata();
    

    【讨论】:

      【解决方案2】:

      如果您知道您的查询,我喜欢在我的子主题的 functions.php 中创建一个镜头代码来创建它。您可以传递参数来创建不同的输出,并且您可以在您的网站的任何地方使用这样的简码。

      【讨论】:

        猜你喜欢
        • 2016-11-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多