【问题标题】:Wordpress multi loop and paginationWordpress 多循环和分页
【发布时间】:2016-03-27 06:37:19
【问题描述】:

您好,我目前正在做这个项目

bsearch

我想为前 2 个帖子创建 2 个样式的帖子,为最后 4 个帖子创建另一个样式。

这是我正在使用的代码。

<?php
    $args = array( 'posts_per_page' => 2, 'category' => 5 );
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>

// content of the first 2 post here //

<?php endforeach; wp_reset_postdata();?>

<?php
    $args = array( 'posts_per_page' => 4, 'category' => 5,'offset' => 2 );
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>

// content of the last 4 post here //

<?php endforeach; wp_reset_postdata();?>

我搜索了,我知道通过这种方式页面分页将不起作用。 但是我只知道一些基本的wordpress和php编码。

谁能帮我解决这个问题?

这是我在PSD做的设计

【问题讨论】:

    标签: php wordpress pagination


    【解决方案1】:
    <?php $args = array( 'posts_per_page' => 2, 'category' => 5 );
     $myposts = get_posts( $args );
    $count = 1;
    if($myposts->have_posts()): while($myposts->have_post): $myposts->the post();
           if($count < 3 ){
    //content and style of the first two post 
    $count++;
    }
    else{
    //content and style of the rest of the post
    $count++;
    }
    endwhile;
    endif;
    ?>
    

    这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-18
      • 2016-04-11
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      • 1970-01-01
      相关资源
      最近更新 更多