简体   繁体   English

在首页上显示10篇博客文章,在其后显示9篇博客文章

[英]Display 10 blog posts on first page and 9 thereafter

I'm using the "bones" theme on WordPress. 我在WordPress上使用“骨骼”主题。 On my blog page I'm trying to have it with 9 blog posts displayed in 3 columns, but on the first page have 10 blog posts with the first (most recent) one being enlarged to span all 3 columns. 在我的博客页面上,我试图将其显示为3列,其中显示9个博客文章,但在第一页上,则显示10个博客文章,其中第一个(最新的)文章被放大以覆盖所有3列。

What is the best way to display 10 posts on the first page and 9 thereafter without messing up the pagination? 在首页上显示10个帖子,在其后显示9个帖子的最佳方法是什么?

Here's my code: (I removed all the HTML and what-not because I assume it's not needed) 这是我的代码:(我删除了所有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; ?>

I haven't really experimented with it as I don't have the page function set up - but try this 我没有真正尝试过它,因为我没有设置页面功能-但是尝试一下

<?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(); }?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM