第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 wordpress 循環(huán)的結(jié)果周圍包裹一個(gè) div,但不包括前 2 個(gè)

在 wordpress 循環(huán)的結(jié)果周圍包裹一個(gè) div,但不包括前 2 個(gè)

PHP
UYOU 2021-06-19 18:06:18
我有一個(gè)自定義帖子類型的循環(huán)。我為每個(gè)帖子帶回了一個(gè)標(biāo)題、圖像和內(nèi)容塊。我想將光滑的滑塊應(yīng)用于結(jié)果以創(chuàng)建光滑的輪播,但我不想包含循環(huán)的前兩個(gè)結(jié)果 - 所以我需要為結(jié)果創(chuàng)建一個(gè)父 div 但只在之后啟動(dòng)該 div前兩個(gè)結(jié)果。我已經(jīng)嘗試了在循環(huán)計(jì)數(shù)上查詢結(jié)果的方法,以將一個(gè)類僅應(yīng)用于前兩個(gè)結(jié)果,但這并沒有真正實(shí)現(xiàn)我所追求的。<div class="wrapper_for_news_items">  <?php $posts = get_posts(array(    'posts_per_page'    => -1,    'post_type'         => 'news',    'order' => 'DESC'));if( $posts ): ?>    <?php $post = $posts[0]; $c=0; ?>    <?php foreach( $posts as $post ):         setup_postdata( $post );        ?>    <div class="treatment_block news_block <?php $c++; if($c == 1) { echo ' featured'; } elseif($c == 2) { echo ' featured'; } ?>">    <h2  class="block_title above"> <?php the_title( '' ); ?></h2>     <h3 class="post_date top">      <?php echo get_the_date() ?>    </h3>      <div class="post_icon" style="background-image: url('<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.    the_post_thumbnail_url($post_id, 'thumbnail');} ?>');">      <button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>      </div>            <h2  class="block_title below"> <?php the_title( '' ); ?></h2>    <h3 class="post_date bottom">      <?php echo get_the_date() ?>    </h3>            <p class="excerpt">            <?php the_excerpt( '' ); ?>            </p>      </div>    <?php endforeach; ?>    <?php wp_reset_postdata(); ?>                           <?php else : ?>                        No News Found!<?php endif; ?><!-- end of news loop -->            </div> <!-- treatment news block wrapper -->
查看完整描述

1 回答

?
開滿天機(jī)

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊

您可以只創(chuàng)建 2 個(gè)循環(huán)。將第一個(gè)用于特色輸出,第二個(gè)用于輪播。


<div class="wrapper_for_news_items">

  <?php 

$args_with_two_posts = array(

    'posts_per_page'    => 2,

    'post_type'         => 'news',

    'order'             => 'DESC'

);

$query_with_two_posts = new WP_Query( $args_with_two_posts );


if( $query_with_two_posts->have_posts ) : 

  while ( $query_with_two_posts->have_posts ) : $query_with_two_posts->the_posts; ?>



  <div class="treatment_block news_block featured">

    <h2 class="block_title above">

      <?php the_title( '' ); ?>

    </h2>

    <h3 class="post_date top">

      <?php echo get_the_date() ?>

    </h3>

    <div class="post_icon" style="background-image: url('<?php 

if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.

    the_post_thumbnail_url($post_id, 'thumbnail');

?>');">

      <button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>

    </div>

    <h2 class="block_title below">

      <?php the_title( '' ); ?>

    </h2>

    <h3 class="post_date bottom">

      <?php echo get_the_date() ?>

    </h3>

    <p class="excerpt">

      <?php the_excerpt( '' ); ?>

    </p>


  </div>




  <?php endwhile; ?>

  <?php wp_reset_postdata(); ?>


  <?php else : ?> No News Found!

  <?php endif; ?>

  <!-- end of 2 post initial news loop -->

</div>

<!-- treatment news block wrapper -->



<?php


  // Start your second loop containing the slickslider content

  

?>




<div class="wrapper_for_news_carousel_items">

  <?php 

$args_with_all_posts = array(

    'posts_per_page'    => -1,

    'offset'            => 2 // Offset the 2 initial posts

    'post_type'         => 'news',

    'order'             => 'DESC'

);

$query_with_two_posts = new WP_Query( $args_with_all_posts );


if( $args_with_all_posts->have_posts ) : 

  while ( $args_with_all_posts->have_posts ) : $args_with_all_posts->the_posts; ?>



  <div class="treatment_block news_block">

    <h2 class="block_title above">

      <?php the_title( '' ); ?>

    </h2>

    <h3 class="post_date top">

      <?php echo get_the_date() ?>

    </h3>

    <div class="post_icon" style="background-image: url('<?php 

if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.

    the_post_thumbnail_url($post_id, 'thumbnail');

?>');">

      <button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>

    </div>

    <h2 class="block_title below">

      <?php the_title( '' ); ?>

    </h2>

    <h3 class="post_date bottom">

      <?php echo get_the_date() ?>

    </h3>

    <p class="excerpt">

      <?php the_excerpt( '' ); ?>

    </p>


  </div>




  <?php endwhile; ?>

  <?php wp_reset_postdata(); ?>


  <?php else : ?> No News Found!

  <?php endif; ?>

  <!-- end of news loop -->

</div>

<!-- treatment news carousel items -->

或者您可以計(jì)算循環(huán)中的帖子并在第三個(gè)帖子之前和最后一個(gè)帖子之后指定一個(gè)包裝器以創(chuàng)建輪播。


<div class="wrapper_for_news_items">

  <?php 

$args_with_two_posts = array(

    'posts_per_page'    => 2,

    'post_type'         => 'news',

    'order'             => 'DESC'

);

$query = new WP_Query( $args_with_two_posts );


$counter = 1; // Set the counter


if( $query->have_posts ) : 

  while ( $query->have_posts ) : $query->the_posts; 

  

  if ( $count == 3 ) { echo '<div class="slick-slider">'; };

  ?>



  <div class="treatment_block news_block">

    <h2 class="block_title above">

      <?php the_title( '' ); ?>

    </h2>

    <h3 class="post_date top">

      <?php echo get_the_date() ?>

    </h3>

    <div class="post_icon" style="background-image: url('<?php 

if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.

    the_post_thumbnail_url($post_id, 'thumbnail');

?>');">

      <button class="post__link but" rel="<?php the_ID(); ?>">READ MORE</button>

    </div>

    <h2 class="block_title below">

      <?php the_title( '' ); ?>

    </h2>

    <h3 class="post_date bottom">

      <?php echo get_the_date() ?>

    </h3>

    <p class="excerpt">

      <?php the_excerpt( '' ); ?>

    </p>


  </div>




  <?php 

        $counter++; // Add +1 every loop

        

        if (($query->current_post +1) == ($query->post_count)) {  

          echo '</div>'; // This is the last post 

        }

        endwhile; 

  ?>

  <?php wp_reset_postdata(); ?>


  <?php else : ?> No News Found!

  <?php endif; ?>

  <!-- end of news loop -->

</div>

<!-- treatment news block wrapper -->


查看完整回答
反對(duì) 回復(fù) 2021-06-25
  • 1 回答
  • 0 關(guān)注
  • 149 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)