首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WordPress post循环有人吗?

WordPress post循环有人吗?
EN

Stack Overflow用户
提问于 2017-02-16 06:29:08
回答 1查看 46关注 0票数 1

我想知道是否有任何方法可以使用WordPress帖子计数器来显示最多10个帖子,每个帖子使用相同的css类,我在下面的代码中做了一个,但是它只显示了两个,当我把帖子数设为4的时候,它不符合我创建的css规则。这就是我已经走了多远。

代码语言:javascript
复制
<div class="col-md-12 featt big-grid">
<div class="container-fluid no-padding">
  <?php
  $args = array(
    'post_type' => '',
    'category_name' => '',
    'posts_per_page' => '2'
  );
  $query = new WP_Query( $args );
  if ( $query->have_posts()) : 
    $i = 0; 

    while( $query->have_posts() ) : 
      $query->the_post();
    $i++;
        if($i <= 2) {
          if($i == 1) {
  ?>
            <div class="big-pane col-xs-6">
            <div class="the-big-pane image">
            <?php the_post_thumbnail();?>
            </div>
            <div class="big-pane overlay">

              <div class="the-big-pane-content">
               <div class="the-cont-cat">
  <span class="the-content-cat-bt">  <?php $category = get_the_category(); if ($category) 
                { echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');}  ?></span>  <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
 </div>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); echo" ".$i?></a></h1>
                <span class="the-content-post-data"><span class="the-auth-post-image-content" style="padding-top: 0px !important;"> <?php echo get_avatar( get_the_author_meta( 'user_email' ), 100 ); ?> </span> By <a href="#"><?php the_author_posts_link(); ?></a> <span class="the-content-post-date"> <i class="fa fa-clock-o the-content "></i><?php the_time('jS M, Y') ?></span> </span>
              </div>
            </div>
            </div>

            <div class="big-pane col-xs-6">
            <?php 
            } 
          else { ?>
            <div class="the-big-pane image">
            <?php the_post_thumbnail();?>
            </div>
            <div class="big-pane overlay">

              <div class="the-big-pane-content">
               <div class="the-cont-cat">
   <span class="the-content-cat-bt">  <?php $category = get_the_category(); if ($category) 
                { echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');}  ?></span>  <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
   </div>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); echo" ".$i?></a></h1>
                <span class="the-content-post-data"><span class="the-auth-post-image-content" style="padding-top: 0px !important;"> <?php echo get_avatar( get_the_author_meta( 'user_email' ), 100 ); ?> </span> By <a href="#"><?php the_author_posts_link(); ?></a> <span class="the-content-post-date"> <i class="fa fa-clock-o the-content "></i><?php the_time('jS M, Y') ?></span> </span>
              </div>
            </div>
            </div>

            <?php 
            if($i == 2){ ?> 
              </div>

              <?php 
            }
          }
        }


    endwhile; 
    else: 
      echo "<p>Sorry no post found :(!</p>"; 
  endif; 
  wp_reset_postdata(); ?>               
   </div>           
EN

回答 1

Stack Overflow用户

发布于 2017-02-16 06:31:23

您需要更改此设置

代码语言:javascript
复制
 $args = array(
    'post_type' => '',
    'category_name' => '',
    'posts_per_page' => '2'
  );

以反映posts_per_page中的帖子数量

代码语言:javascript
复制
 $args = array(
    'post_type' => '',
    'category_name' => '',
    'posts_per_page' => '10'
  );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42261315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档