【问题标题】:WordPress - pagination on template page?WordPress - 模板页面上的分页?
【发布时间】:2012-10-08 11:22:53
【问题描述】:

我正在使用 WordPress 模板构建我的网站,以便精细控制每个模板的外观。

我的新闻页面上有我的循环,可以从帖子中提取帖子。

工作正常,至少我是这么认为的。

<?php 
/*
    Template Name: News
*/
?>

<?php get_header(); ?>
<div id="main-content">

<?php get_sidebar(); ?>
<?php query_posts ("posts_per_page=4"); ?>

<?php if (have_posts()) : while ( have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

    <div class="entry">
        <?php the_content(); ?>
    </div>
    <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
    <div class="postmetadata">
        <?php the_tags('Tags: ', ', ', '<br />'); ?>
        Posted in <?php the_category(', ') ?> | 
        <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?>
    </div>

</div>

<?php endwhile; endif; ?>

<div class="navigation">
<div class="next-posts"><?php next_posts_link('&laquo; Older Entries') ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>

</div> <!-- end div main-content -->
<?php get_footer(); ?>

显示较旧/较新的条目,但点击它们后,我只会转到同一页面/最新的 4 个帖子。

如何让分页与这样的模板页面一起工作?

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    需要将paged参数添加到query_posts()中才能对结果进行分页:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('posts_per_page=3&paged=' . $paged); 
    ?>
    

    http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

    【讨论】:

      【解决方案2】:
      <div class="navigation">
      <div class="next-posts"><?php next_posts_link('&laquo; Older Entries') ?></div>
      <div class="prev-posts"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
      

      只需将此行放在您的页面中即可。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多