2015-10-12 44 views
0

是否可以将下一个和上一个帖子链接添加到查询来自一个类别的帖子并在每个页面上显示该类别的一个帖子的页面?Paginate Wordpress中的帖子的类别页面

这是我目前有:

 <?php query_posts('cat=2&posts_per_page=1'); ?> 

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

      <!-- article --> 
      <article class="overlay" id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

       <div class="inner"> 

        <div class="gallery" style="background-image: url(<?php the_field('image'); ?>);"> 
         <div class="close" data-home="<?php echo home_url(); ?>"> 
          <span class="oi" data-glyph="x"></span> 
         </div> 
        </div> 

        <div class="copy"> 
         <h2><?php the_title(); ?></h2> 
         <?php the_field('news_content'); ?> 
         <a href="**NEXT_POST_IN_SAME_CATEGORY**">Next</a> 

        </div> 

       </div> 

      </article> 
      <!-- /article --> 

     <?php endwhile; ?> 
+0

'query_posts'打破主查询对象和分页,所以你的代码将无法工作。你应该**从来没有**使用'query_posts' –

回答

0

尝试这似乎是只为我工作的解决方案,如果有人需要一个模板:

<?php get_header(); ?> 

    <main role="main"> 
    <!-- section --> 
    <section> 

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

     <!-- article --> 
     <article class="overlay" id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

      <div class="inner"> 

       <div class="copy"> 
        <h2><?php the_title(); ?></h2> 
        <?php the_field('news_content'); ?> 
        <?php the_field('copy'); ?> 
        <br> 
        <br> 
        <?php next_post_link('%link', 'Next', TRUE, 'post_format'); ?> | <?php previous_post_link('%link', 'Previous', TRUE, 'post_format'); ?> 
       </div> 

      </div> 

     </article> 
     <!-- /article --> 

    <?php endwhile; ?> 

    <?php else: ?> 

     <!-- article --> 
     <article> 

      <h1><?php _e('Sorry, nothing to display.', 'html5blank'); ?></h1> 

     </article> 
     <!-- /article --> 

    <?php endif; ?> 

    </section> 
    <!-- /section --> 
    </main> 

<?php get_footer(); ?> 
相关问题