用wp_pagenavi查询?

时间:2012-12-14 20:27:15

标签: php wordpress

我使用以下代码查询所有帖子

<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
query_posts(array(
'post_type'         => 'san-pham',                          'posts_per_page'    => 8,
'paged'         => $paged,
'order'         => 'DESC',
)
);
?>
<?php $i=1; while(have_posts()) : the_post(); ?>
//
<?php $i++; endwhile ?>
<?php if (function_exists('wp_pagenavi')) {
wp_pagenavi(); } ?>

现在我想查询特定类别的所有帖子。我该怎么做?

2 个答案:

答案 0 :(得分:0)

您可以在query_posts数组中添加category_name

例如

query_posts( 'showposts = 3及CATEGORY_NAME =博客&安培;的OrderBy = ID&安培;寻呼=' $分页);

答案 1 :(得分:0)

<?php 
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $args = array(
        'post_type'  => 'san-pham',  
        'post_status' => 'publish',
        'paged'         => $paged,
        'posts_per_page' => 8,
        'order'         => 'DESC',
);
    $query = new WP_Query($args);  
        if ($query->have_posts()):
            while ( $query->have_posts() ):
                $query->the_post(); 
?>      
        //content
 <?php endwhile; ?>

    <?php if (function_exists('wp_pagenavi')): ?>
        <?php wp_pagenavi( array( 'query' => $query ) ); ?>
    <?php endif; ?>