wordpress query_posts问题

时间:2011-09-21 17:14:26

标签: wordpress

所以我有一个自定义模板,显示特定类别的帖子(取决于get_post_meta('Category'))。

该页面可以完美地显示来自“新闻”类别的帖子。但是,使用完全相同的代码(减去其显示方式),它对日历类别中的帖子的分页存在问题。基本上,日历帖子的第一页正确显示,然后当您点击“下一页”时,网址会更新到第2页,但页面上的帖子相同。

以下是代码:

<?php $category = get_post_meta($post->ID, 'Category', true); ?>
<?php $cat = get_cat_ID($category); ?>

<?php $paged = (get_query_var('page')) ? get_query_var('page') : 1; ?>

<?php $args = array(
        'cat' => $cat,
        'paged' => $paged
    );
?>

<?php query_posts($args); ?>

<?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

        <!-- If its a Calendar page -->
        <?php if ($cat == 1): ?>
            <div class='entry'>
                <!-- List all Calendar info and Custom Fields -->
                <ul>
                    <li><h3><?php the_title(); ?></h3></li>
                    <li><?php the_content(); ?></li>

            <!-- ...And displays other data, etc..... -->
                </ul>
            </div>

        <?php else: ?>

            <div class='entry'>
                <ul>
                    <li><?php the_title(); ?></a></h3></li>
                    <li><?php the_time('F jS, Y'); ?></li>
                    <li><?php the_content(); ?></li>

            <!-- And display other data, etc .... -->
                </ul>
            </div>
        <?php endif; ?>

    <?php endwhile; ?>

    <!-- Posts Nav Links -->
    <?php posts_nav_link(' | ', '&laquo; Newer Entries', 'Older Entries &raquo;'); ?>

<?php endif; ?>

1 个答案:

答案 0 :(得分:0)

这很可能与您在自定义模板中为paged设置query_posts()参数的方式有关。

在此处详细了解:http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html

简而言之,您可能需要使用get_query_var('paged')