2

我有一个“小屋”的自定义帖子类型,有类别(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

这是我完全迷路的地方!:

  • 我想在 Visual Composer 中选择基于一个或多个类别来缩小数据源的范围(记住它们是自定义帖子类型类别)。
  • 我想我需要在我的第二个块 (php/html) 中添加额外的代码,以确保只显示选择的类别。

帮助!我一直在做从我能找到的任何可能有帮助的代码中剪切-n-粘贴的菜鸟技巧,经过一天之后我仍然失败了!

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

谢谢京东

4

0 回答 0