2012-11-20 183 views
0

我有一个存档页面,设置为显示类别的具体帖子。但是,不是仅显示分类页面上给定类别的帖子,而是显示所有帖子。有关示例,请参阅hereWordPress的类别模板显示所有类别的帖子,而不是特定的类别帖子

这是我在我的archive.php页面上使用的代码。我知道这是不恰当的使用循环,但我不知道如何解决它。谢谢您的帮助。

<?php get_header(); ?> 
    <div id="content"> 
     <div id="inner-content" class="wrap clearfix"> 
      <h1 class="blogTitle" style="margin:10px 0 3px 0;">Blog Title</h1> 
       <nav class="blogNav" role="navigation"> 
        <?php bones_blog_nav(); // Adjust using Menus in Wordpress Admin ?> 
       </nav> 
       <div id="main" class="eightcol first clearfix" role="main"> 
        <div class="catwhiteBg"> 
         <?php if (is_category()) { ?> 
         <h1 class="catTitle"> 
          <span><?php _e("", "bonestheme"); ?></span> <?php single_cat_title(); ?> 
         </h1> 
         <?php echo category_description($category_id); ?> 

         <?php } elseif (is_author()) { ?> 
          <div class="authorTop"> 
           <?php 
           $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); 
           ?> 
           <div class="author-pic"><?php echo get_avatar($curauth->user_email, '80'); ?></div> 
           <div class="author-name"><span style="font-weight: 200; color: #575757;">POSTS BY:</span> 
             <?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?> 
           </div> 
           <div class="author-bio"><?php echo $curauth->description; ?></div> 
           <a href="<?php echo $curauth->twitter; ?>" title="Twitter"><div class="author-twitter"><span>twitter</span></div></a> 
          </div> 

         <?php } elseif (is_day()) { ?> 
          <h1 class="archive-title h2"> 
           <span><?php _e("Daily Archives:", "bonestheme"); ?></span> <?php the_time('l, F j, Y'); ?> 
          </h1> 

         <?php } elseif (is_month()) { ?> 
          <h1 class="archive-title h2"> 
           <span><?php _e("Monthly Archives:", "bonestheme"); ?></span> <?php the_time('F Y'); ?> 
          </h1> 

         <?php } elseif (is_year()) { ?> 
          <h1 class="archive-title h2"> 
           <span><?php _e("Yearly Archives:", "bonestheme"); ?></span> <?php the_time('Y'); ?> 
          </h1> 
         <?php } ?> 
        </div> 

        <div class="psts"> 
         <?php 
         global $wp_query; 

         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

         if (get_query_var('paged')) { 

         $paged = get_query_var('paged'); 

         } elseif (get_query_var('page')) { 

         $paged = get_query_var('page'); 

         } else { 

         $paged = 1; 

         } 

         query_posts(array('posts_per_page' => '8','paged'=>$paged)); 
         ?> 

         <?php 
         $count = 1; 

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

         <div class="sixcol small pst<?php if ((isset($count)) && ($count % 2 == 0)) { echo ' last';} // same logic to add class of last to last item in row of two ?>" id="post-<?php the_ID(); ?>"> 
          <article id="post-<?php the_ID(); ?>" role="article"> 
           <div class="thumb-wrapper mobile"> 
            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src(get_post_thumbnail_id(),'post-thumb'); echo '<img src="' . $image_src[0] . '" width="100%" class="post-thumb" />'; } ?></a> 

            <header class="post-thumb-header"> 
             <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><h2 class="post-title"><?php the_title(); ?></h2></a> 
            </header> <!-- end article header --> 
            <p class="meta"><?php the_category(', '); ?></p> 
           </div> 

           <section class="mobile-content"> 
            <?php the_excerpt(); ?> 
           </section> 
          </article> <!-- end article --> 
         </div> 

         <?php $count++; ?> 

         <?php endwhile; ?> 

         <nav class="wp-prev-next"> 
          <?php echo rb_pagination(); ?> 
         </nav> 
        </div> <!-- end .psts -->           
       </div> <!-- end #main --> 

      <?php get_sidebar(); // sidebar 1 ?> 

     </div> <!-- end #inner-content --> 

    </div> <!-- end #content --> 

<?php get_footer(); ?> 

回答

1

我认为你覆盖了原来的查询与这条线:

query_posts(array('posts_per_page' => '8','paged'=>$paged)); 

你可以换用此此行,让我知道结果?

global $query_string; 
query_posts($query_string . "&posts_per_page=8&paged=$paged"); 

如果失败尝试:

query_posts(array('posts_per_page' => '8','paged'=>$paged, 'cat' => $category_id)); 
相关问题