WP Pagination没有循环播放帖子

时间:2014-01-27 05:27:12

标签: php wordpress pagination

我正在尝试修复其他人创建的WP Pro Real Estate 3上的子主题。在主题的其他地方,发生了不同的内容导航。我曾尝试连接一个插件进行分页,它也不会遍历帖子。 URL更新,但显示的10个帖子始终相同。

以下是该页面的代码。我应该先在哪里找出可能导致问题的原因?

  
        <?php global $ct_options;
            if($ct_options['ct_layout'] == 'left-sidebar') {
            get_sidebar();
        } ?>

        <section id="blog" class="ten columns marT20 left">
        <h2> Blog </h2>

        <?php query_posts( 'cat=-39' ); ?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

                <article id="post-<?php the_ID(); ?>" <?php post_class('left clear'); ?>>                        

                    <?php if ( has_post_thumbnail() ) {
                                the_post_thumbnail();
                                    } ?>

                    <h2 class="entry-title marB18"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <?php the_excerpt(); ?>
                    <br/>
                    <?php ct_read_more_link(); ?>
                    <!-- <a href="<?php the_permalink(); ?>" class="read-more" />Read More</a> -->

                <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?>
                </article>

            <?php endwhile; endif; ?>

              <?php if (function_exists("pagination")) {
pagination($additional_loop->max_num_pages);

 } ?>     

        </section>


        <div class="sidebar six columns marT20 left">
            <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Sidebar Blog') ) :else: endif; ?>

            <div id="sidebar-inner">
                <aside class="widget widget_text left" id="about-nic-nav"><h4>About Nicaragua</h4>
                    <div class="textwidget">
                    <?php query_posts( 'cat=39' ); ?>
                    <ul>
                    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                    <?php endwhile; endif; ?>
                    </ul>
                    </div>
                </aside>
                <div class="clear"></div>
            </div>


        </div>

1 个答案:

答案 0 :(得分:0)

在<循环之后看到它被称为,我建议你插件中的pagination()函数只添加页码。它实际上并没有设置您的分页查询。

为此,您需要确保在查询中包含paged参数。

例如,要按日期顺序显示每页发布的5篇帖子,请在之前包含

$args = array(
    'orderby'        => 'date',
    'order'          => DESC,
    'paged'          => get_query_var('paged'),
    'posts_per_page' => 5,
    'post_type'      => 'post',
    'post_status'    => 'publish'
);
query_posts($args);

查看Pagination ParametersWP_Query Codex部分以获取更多信息。

另外,如果您不确定是什么,请查看Codex for The Loop

其他信息

顺便说一句,我在你的代码中注意到你使用The Loop两次。有很多情况下这是必要的,但是在两种情况下,你的情况似乎是相同的,所以没有必要回忆query_posts()。相反,在The Loop的第一个循环结束时调用wp_reset_query()(这总是我们那个人的习惯),它会将指针设置回The Loop的开头,并节省你的时间。您不必再次查询数据库。

但是,如果您确实要求“循环”输出不同的帖子,则应使用new WP_Query()代替(说实话,我建议始终使用它而不是the_query(),因为它更容易使用如果需要挂钩)。例如 -

$args = array(
    'cat' => 10,
    'post_status' => 'scheduled'
);
$scheduled_posts = new WP_Query($args);

if($scheduled_posts->have_posts()) : while($scheduled_posts->have_posts()) : $scheduled_posts->the_post();
?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <h2><?php the_title(); ?> </h2>
            <div><?php the_content(); ?></div>
        </div>
<?php
    endwhile;
endif;

wp_reset_query();