2014-01-27 88 views
0

我想修复其他人创建的WP Pro房地产3上的儿童主题。在主题的其他地方,有不同的内容导航发生。我尝试过为分页插入一个插件,并且它也不会在帖子中循环。 URL更新,但显示的10个帖子总是相同的。WP分页不通过帖子循环

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

 <?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> 

回答

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); 

退房的WP_Query Codex的更多信息,Pagination Parameters部分。如果您不确定这是什么,请检查Codex for 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(); 
+0

谢谢你!我之前已经看到过这些参数,但是我一定是错过了一部分,以致无法工作。它虽然现在工作!干杯! – crysmeg

+0

不客气。 –