我有一个自定义的'Cottages'类型,有类别(1张床,2张床,3张床) .

我可以在我的functions.php中使用以下vc_map获取要在Visual Composer中显示的元素:

// Cottages List
if(function_exists('vc_map')){
   vc_map( array(
   "name" => __("My Cottages List", 'archi'),
   "base" => "cottageslist",
   "class" => "",
   "category" => 'My Elements',
   "icon" => "icon-rtcvc",
   "params" => array(      
      array(
         "type" => "textfield",
         "holder" => "div",
         "class" => "",
         "heading" => "Show how many cottages per page?",
         "param_name" => "number",
         "value" => "",
         "description" => __("Add Number -1 for show all post.", 'archi')
      ),  
    )
    ));
}'

然后,我知道它显示以下php / html代码(也会错开特征图像行,发布内容...发布内容,功能图像)

// Cottages List start
add_shortcode('cottageslist','cottageslist_func');
function cottageslist_func($atts, $content = null){
    extract(shortcode_atts(array(
        'number'    =>      '',
    ), $atts));
    $number1 = (!empty($number) ? $number : 4);
    ob_start(); 
?>

    <?php
        $i = 0;
        $args = array(
            'post_type' => 'cottages',
            'posts_per_page' => $number1,
        );
        $cottages = new WP_Query($args);
        if($cottages->have_posts()) : while($cottages->have_posts()) : $cottages->the_post(); $i++;
    ?>


        <section class="side-bg no-padding service-list" id="section-service-<?php echo esc_attr($i); ?>">

            <?php if ($i % 2 == 1) { ?>

            <div class="image-container col-md-5 pull-left" data-delay="0">
                <div class="background-image" style="background-image:url('<?php the_post_thumbnail_url( 'full' ); ?>');"></div>
            </div>

            <div class="container">
                <div class="row">
                    <div class="inner-padding">
                        <div data-wow-delay=".5s" class="col-md-6 col-md-offset-6 wow fadeInRight">
                            <h3 class="id-color"><a class="" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <?php the_excerpt(); ?>
                            <div class="spacer-single"></div>
                            <a class="btn-line" href="<?php the_permalink(); ?>"><?php _e('Read More', 'archi') ?></a>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>

            <?php }else{ ?>

            <div data-delay="0" class="image-container col-md-5 col-md-offset-7 pull-right right0">
                <div class="background-image" style="background-image:url('<?php the_post_thumbnail_url( 'full' ); ?>');"></div>
            </div>

            <div class="container">
                <div class="row">
                    <div class="inner-padding">
                        <div data-wow-delay=".5s" class="col-md-6 wow fadeInLeft">
                            <h3 class="id-color"><a class="" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            <?php the_excerpt(); ?>
                            <div class="spacer-single"></div>
                            <a class="btn-line" href="<?php the_permalink(); ?>"><?php _e('Read More', 'archi') ?></a>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <?php } ?>

        </section>            

    <?php endwhile; wp_reset_postdata(); endif; ?>  

<?php
    return ob_get_clean();
}   
// Cottages List start

Here's where I'm completely lost!:

  • 我想在Visual Composer中选择基于一个或多个类别缩小数据源(请记住它们是自定义的帖子类型类别) .

  • 我想在我的第二个块(php / html)中需要额外的代码以确保只显示所选的类别 .

救命!我一直在用我能找到的任何可能有帮助的代码来做切割粘贴的菜刀技巧,经过一天的努力,我仍然失败了!

是的,我知道VC Post Grid元素会很好地过滤,但是我不喜欢前端的那些Post Grid块只在页面的其余部分完全加载后加载几秒钟 .

谢谢JD