2013-04-29 54 views
0

感謝您的高級任何洞察,我一直在撓我的頭。Wordpress query_posts分頁問題

這是我用來調用主頁上的職位代碼:(www.csmpromo.com)

<div id="home-posts"> 

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    query_posts(array('cat' => 'home', 'types' => $types, 'posts_per_page' => 19, 'paged' => $paged,)); ?> 
    <?php if (have_posts()) : ?> 
    <?php while (have_posts()) : the_post(); ?> 

    <div class="home-post"><a href="<?php the_permalink(); ?>" class="transition"> 
      <div class="home-image"> 
       <?php if (has_post_thumbnail()) { the_post_thumbnail('home-thumb', array('class' => 'home-image')); } else { ?> 
       <img src="<?php bloginfo('template_directory'); ?>/img/fallback.jpg" alt="<?php the_title(); ?>" class="home-image" /> 
       <?php } ?> 
      </div> 
      <?php the_titlesmall('', '<i class="icon-right-open-mini"></i>', true, '80') ?></a> 
       <div class="home-post-meta"> 
        <i class="icon-user" style="font-size:7px; color:#9B362F"></i> <?php the_author_link(array('class' => 'home-author')); ?></span> 
        <i class="icon-feather" style="font-size:7px; color:#9B362F"></i> <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> 
        <i class="icon-chat" style="font-size:7px; color:#9B362F"></i> <?php comments_number('0 Comments', '1 Comments', '% Comments');?></div> 
       </div> 

    <?php endwhile; endif; ?> 

    <div class="navigation"> 
     <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div> 
     <div class="alignright"><?php next_posts_link('More &raquo;') ?></div> 
    </div> 

    <?php wp_reset_query(); ?> 

</div> 

我讀過有使用query_posts分頁功能,但每一個解決方案,很多問題我試過失敗了。

謝謝!

+0

你的問題不清楚 – 2013-04-29 19:55:06

+0

你使用這段代碼到底是什麼問題? – cha0site 2013-04-29 20:03:51

+0

你試過了wp_reset_postdata();而不是wp_reset_query(); ?? – 2013-04-29 20:43:23

回答

0

我們推薦放棄query_posts使用,離開家頁完好的原始查詢,並從functions.php文件修改查詢,使用pre_get_posts,如:

add_action('pre_get_posts','so16286638_pre_get_posts'); 
function so16286638_pre_get_posts($query) 
{ 
    if(is_home() && $query->is_main_query()){ 
     $query->set('cat', 'home'); 
     $query->set('post_type', 'post'); 
     // more params 
    } 
    return $query; 
} 

更多信息:https://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts