如何在wordpress的else循环“ the loop”中插入一些代码?

时间:2018-07-05 06:54:58

标签: wordpress loops

<section class="container-fluid jp-section jp-bg-red jp-color-white h-m-md-auto first" data-section-label="Get Paid">
        <div class="row no-gutters h-100 h-m-md-auto">
            <div class="col-lg-6 col-12 ph-100 h-m-md-auto jp-p-l-0 jp-p-r-0 jp-p-t-90 jp-p-b-80 jp-md-p-t-20 jp-md-p-b-20">
                <div class="vertical-title h-100 float-left">
                    <div class="wrapper">
                        <h2>YOUTH ARTISTS</h2>
                    </div>
                </div>


                <?php query_posts('post_type=jxta_shop&posts_per_page=6'.'&paged='.$paged);?> 
                <?php if (have_posts()): while (have_posts()) : the_post(); ?>

                      <!-- article -->
                      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>


                <div class="misson-wrapper h-100 h-m-md-auto">
                    <div class="row h-100 h-m-md-auto">
                        <div class="col-12">
                            <div class="owl-carousel owl-theme" data-childslider="#homeSectionImageSlider" data-dots="#homeSectionDots">
                                <div class="item jp-bg-red">

                                    <p class="jp-font-journal display-3 text-uppercase"><?php echo'<p class="jp-font-journal display-3 text-uppercase" style="width:80%;" >'. get_field('slider_header_1') .'</p>' ?>
                                    </p>

                                    <p class="h2 jp-font-journal mb-4"><?php echo'<p class="h2 jp-font-journal mb-4" style="width:80%;" >'. get_field('slider_description_1') .'</p>' ?>
                                    </p>

                                    <p class="h2 jp-font-journal"></p>

                                    <?php 
                                        $slider_button_link_1 = get_field('slider_button_link_1');

                                        if( $slider_button_link_1 ): ?>
                                    <a class="btn btn-outline-white rounded-0" style="color:#000;" href="<?php echo $slider_button_link_1; ?>"><b>READ MORE</b></a>
                                    <?php endif; ?> 

                                    <br/>
                                </div>
                                <div class="item jp-bg-red">
                                    <p class="jp-font-journal display-3 text-uppercase"><?php echo'<p class="jp-font-journal display-3 text-uppercase" style="width:80%;" >'. get_field('slider_header_2') .'</p>' ?></p>

                                    <p class="h2 jp-font-journal mb-4"><?php echo'<p class="h2 jp-font-journal mb-4" >'. get_field('slider_description_2') .'</p>' ?></p>

                                    <?php 
                                        $slider_button_link_2 = get_field('slider_button_link_2');

                                        if( $slider_button_link_2 ): ?>
                                    <a class="btn btn-outline-white rounded-0" style="color:#000;" href="<?php echo $slider_button_link_2; ?>"><b>READ MORE</b></a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                        <div id="homeSectionDots" class="col-12 align-self-end jp-owl-dots white"></div>
                    </div>
                </div>


                <div class="col-lg-6 ph-100 col-12">
                    <div id="homeSectionImageSlider" class="owl-carousel owl-theme h-100">

                        <div class="item h-100 bg-cover bg-bottom" style="background-image:url('<?php the_field( 'slider_image_1'); ?>')">
                        </div>

                        <div class="item h-100 bg-cover bg-bottom" style="background-image:url('<?php the_field( 'slider_image_2'); ?>')">
                        </div>
                     </div>
                </div>     



      </article>
      <!-- /article -->

    <?php endwhile; ?>

    <?php else: ?>

      <!-- article -->
      <article>

        <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>

      </article>
      <!-- /article -->

    <?php endif; ?>



</div>
</div>
</section>  

这是我的代码。我正在使用WordPress循环来显示帖子内容。但是我想在else循环中放入一些代码。现在,如果我在else循环中放入任何代码,它不会像if循环那样显示。它显示“很抱歉,没有任何显示。”我想将以下代码放入else循环中。

<div class="item jp-bg-red">

     <p class="jp-font-journal display-3 text-uppercase"><?php echo'<p class="jp-font-journal display-3 text-uppercase" style="width:80%;" >'. get_field('slider_header_1') .'</p>' ?>
     </p>

     <p class="h2 jp-font-journal mb-4"><?php echo'<p class="h2 jp-font-journal mb-4" style="width:80%;" >'. get_field('slider_description_1') .'</p>' ?>
      </p>

      <p class="h2 jp-font-journal"></p>

      <?php 
         $slider_button_link_1 = get_field('slider_button_link_1');

             if( $slider_button_link_1 ): ?>
             <a class="btn btn-outline-white rounded-0" style="color:#000;" href="<?php echo $slider_button_link_1; ?>"><b>READ MORE</b></a>
                                    <?php endif; ?> 

                  <br/>
</div>

如何做到?

1 个答案:

答案 0 :(得分:0)

使用WP_Query

代替query_posts
$args = array(
    'post_type' => 'jxta_shop',
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {

} else {

}