【问题标题】:Display 10 blog posts on first page and 9 thereafter在首页显示 10 篇博文,之后显示 9 篇
【发布时间】:2013-05-30 18:48:07
【问题描述】:

我在 WordPress 上使用“骨骼”主题。在我的博客页面上,我试图让它在 3 列中显示 9 篇博客文章,但在第一页上有 10 篇博客文章,第一个(最近的)一篇被放大以跨越所有 3 列。

在第一页显示 10 个帖子,然后在不打乱分页的情况下显示 9 个帖子的最佳方式是什么?

这是我的代码:(我删除了所有的 HTML 和其他内容,因为我认为不需要它)

<?php if (have_posts()) : ?>
<?php $post = $posts[0]; $c=0;?>
<?php while (have_posts()) : the_post(); ?>

<?php $c++;
    if( !$paged && $c == 1){
        //code for the first post
    } else {  // THE REST: begin the code for the remainder of the posts ?>

<?php } 
endif; ?>
<?php endwhile; ?>

【问题讨论】:

    标签: php wordpress loops


    【解决方案1】:

    我没有真正尝试过它,因为我没有设置页面功能 - 但试试这个

    <?php 
    $post = $posts[0]; $c=0;
    $c++; if( !$paged && $c == 1){
    $query1 = new WP_Query( array ('posts_per_page' => 1 ) );
    if ($query1-> have_posts()) : while ($query1-> have_posts()) : $query1-> the_post(); ?>
    <?php the_title(); ?>
    <?php endwhile; endif; wp_reset_query();} 
    else{
    $query2 = new WP_Query( array ('posts_per_page' => 9, 'offset' => 1 ) );
    if ($query2-> have_posts()) : while ($query2-> have_posts()) : $query2-> the_post(); ?>
    <?php the_title(); ?>
    <?php endwhile; endif; wp_reset_query(); }?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-29
      • 2023-04-08
      • 1970-01-01
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多