WordPress主题中的分页帖子 [英] Paginate posts in WordPress Theme

查看:95
本文介绍了WordPress主题中的分页帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经盯着这个看了近一个小时,无法正常工作.我正在使用WordPress,并且系统中有12个帖子.在管理员中,我将其设置为每页显示5个帖子.在我的主题中,我试图在底部显示分页(上一页,1、2、3、4,下一页).我在WordPress指南上找到了paginate_links()函数,它不会打印出任何内容...感谢您的帮助:

Alright, I've been staring at this for nearly an hour now and can't get it to work. I'm using WordPress and I have 12 posts in the system. In the admin, I set it to display 5 posts per page. In my theme, I am trying to display pagination (prev,1,2,3,4,next) at the bottom. I found the paginate_links() function on the WordPress guides and it doesn't print anything out... Any help is appreciated:

<?php get_header(); ?>
<div class="middle-container">
    <div class="middle">
        <div class="column main">
            <div class="latest">
            <?php
            $i = 0;
            if (have_posts()):
                while (have_posts() && $i < 1):
                    the_post();
                    ?>
                    <div class="image"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
                    </div>
                    <div class="content">
                    <h1><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
                    <span class="date"><?php the_time('F jS, Y') ?></span>
                    <?php
                    the_excerpt();
                    ?>
                    </div>
                    <?php
                    $i++;
                endwhile;
            endif;
            ?>
            </div>
            <ul class="posts">
            <?php
            $i = 0;
            if (have_posts()):
                while (have_posts() && $i < 4):
                    the_post();
                    ?>
                    <li>
                    <h2><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                    <span class="date"><?php the_time('F jS, Y') ?></span>
                    <?php
                    the_excerpt();
                    ?>
                    </li>
                    <?php
                    $i++;
                endwhile;
            endif;
            ?>
            </ul>
            <?php
            echo paginate_links();
            ?>
        </div>
        <div class="column sidebar"></div>
    </div>
</div>
<?php get_footer(); ?>

对此有更多了解:代码中的第一个while循环获取列表中的第一条帖子,并将其显示在其自己的特殊块中.第二个while循环获取其余4个帖子.这两个while循环都可以正常工作.分页只是没有打印出来.

A little more background on this: The first while loop in the code grabs the first post in the list and displays it in its own special block. The second while loop grabs the remaining 4 posts. Both of these while loops work perfectly fine. The pagination just simply isn't printing out.

推荐答案

似乎Wordpress paginate_links函数需要一个参数.

It appears that the Wordpress paginate_links function expects one argument.

我会尝试他们的默认示例,看看它是否有效.

I would try their default example and see if it works.

<?php
paginate_links(array(
    'base'         => '%_%',
    'format'       => '?page=%#%',
    'total'        => 1,
    'current'      => 0,
    'show_all'     => False,
    'end_size'     => 1,
    'mid_size'     => 2,
    'prev_next'    => True,
    'prev_text'    => __('&laquo; Previous'),
    'next_text'    => __('Next &raquo;'),
    'type'         => 'plain',
    'add_args'     => False,
    'add_fragment' =>  ));
?>

这篇关于WordPress主题中的分页帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆