在WP_Query中添加偏移量到IF语句

时间:2014-12-14 02:23:28

标签: html wordpress loops if-statement wp-query

我想知道是否有办法使用WP_Query获取最新的6个帖子以及基于其类别的Offset帖子。

我有以下代码,但我不确定应该在哪里添加偏移量。

 <?php $the_query = new WP_Query( 'posts_per_page=6&cat=-3,-5' ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if ( in_category( '2' ) ) : ?>
     <div class="post post-monthly"><?php the_post_thumbnail( 'full', array( 'class' => 'post-monthly-image' ) ); ?><a href="<?php the_permalink(); ?>" class="image-overlay"></a>
    <div class="post-monthly-text">
      <h1 class="monthly-header"><a href="<?php the_permalink(); ?>" class="white"><?php the_title(); ?></a></h1>
      <h3 class="monthly-caption"><a href="<?php the_permalink(); ?>" class="white"><?php the_excerpt(); ?></a></h3>
    </div>
  </div>
  <?php else : ?>   
  <div class="post">
    <div class="post-top"></div>
    <div class="post-image-container"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'full', array( 'class' => 'post-image' ) ); ?></a></div>
    <div class="post-container">
      <h2 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <h6 class="post-author"> <a href="<?php the_permalink(); ?>" class="inverted-link"><?php the_author(); ?></a></h6>
      <div class="post-text-container"><?php the_content(); ?></div>
      <h6 class="post-timestamp"> <a href="<?php the_permalink(); ?>" class="inverted-link"><?php the_time('g:ia'); ?> on <?php the_time('D, m/d/y'); ?></a></h6>
      <h6 class="post-category"> <a href="<?php the_permalink(); ?>">Life</a></h6>
    </div>
  </div>
  <?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php endwhile; else : ?>
  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

我希望将Offset添加到in_category('2')IF语句中。

0 个答案:

没有答案