首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在第一页显示10篇博客文章,之后显示9篇

在第一页显示10篇博客文章,之后显示9篇
EN

Stack Overflow用户
提问于 2013-05-31 02:48:07
回答 1查看 159关注 0票数 0

我在WordPress上使用了"bones“主题。在我的博客页面上,我试图将9篇博客文章显示在3栏中,但在第一页上有10篇博客文章,第一篇(最近的)文章被放大到所有3栏。

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

下面是我的代码:(我删除了所有的HTML和其他东西--不是因为我假设它不需要)

代码语言:javascript
复制
<?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; ?>
EN

回答 1

Stack Overflow用户

发布于 2013-05-31 04:11:43

我还没有真正尝试过它,因为我还没有设置页面函数--但是试试这个

代码语言:javascript
复制
<?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(); }?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16843729

复制
相关文章

相似问题

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