开发者

wordpress query_posts problem

开发者 https://www.devze.com 2023-04-06 17:17 出处:网络
So I have a custom template that display posts from a particular category (depending on the get_post_meta(\'Category\')).

So I have a custom template that display posts from a particular category (depending on the get_post_meta('Category')).

The page works flawlessly for displaying posts from a 'News' Category. However, using the exact same code (minus how its displayed), it has problems with the Pagination for posts from the Calendar Category. Basically, the first page of Calendar posts display correctly, and then when you hit 'next page', the url updates to page/2, but the same posts are on the page.

Here's the code:

<?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&g开发者_JS百科t;
                    <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; ?>


More than likely this has to do with how you are setting the paged parameter for query_posts() in a custom template.

Read more about this here: http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html

In a nutshell you may need to use get_query_var('paged').

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号