使用分页查询多个分类

时间:2012-07-31 作者:user1489083

我正在查询多个分类法,对此没有问题,但分页无法解决它,我尝试了很多建议,但都没有成功。这是我的代码

        if ( get_query_var(\'paged\') ) {
            $paged = get_query_var(\'paged\');
        } elseif ( get_query_var(\'page\') ) {
            $paged = get_query_var(\'page\');
        } else {
            $paged = 1;
        }
        if(isset($_POST[\'genre\'])) {
            $myquery[\'tax_query\'] = array(
            \'showposts\' => 20 ,
            \'orderby\' => \'title\',
            \'order\' => \'ASC\',
            \'paged\' => $paged,
            \'relation\' => \'AND\',
            array(
                \'taxonomy\' => \'anime_genre\',
                \'terms\' => $_POST[\'genre\'],
                \'field\' => \'slug\',
                \'operator\' =>\'AND\'
                )
            );
        }
        query_posts($myquery);
            if (have_posts()):
                while (have_posts()):
                    the_post();
                    mystique_post();
                endwhile;
            wp_pagenavi();
            else: ?>
                <h1 class="title error"><?php _e("No posts found","mystique"); ?></h1>
                <p><?php _e("Sorry, but you are looking for something that isn\'t here.","mystique"); ?></p>
            <?php 
            endif; 
我对查询分类法没有问题,但只有分页不起作用

2 个回复
最合适的回答,由SO网友:user1489083 整理而成

我设法解决了自己的问题,但又出现了另一个问题,

    $paged = 1;
    if ( get_query_var(\'paged\') ) $paged = get_query_var(\'paged\');
    if ( get_query_var(\'page\') ) $paged = get_query_var(\'page\');
  $args=array(
\'paged\' => $paged,
\'post_type\'=>\'animes\',
\'post_status\'=>\'publish\',
\'order\'=>\'ASC\',
\'posts_per_page\'=>\'15\',
\'orderby\'=>\'title\',
\'tax_query\'=>array(
    array(
        \'taxonomy\' => \'anime_genre\',
        \'terms\' => array(\'drama\',\'romance\'),
        \'field\' => \'slug\',
        \'operator\' =>\'AND\',
    ),

)
);

    print_r($args);
    $loop = new WP_Query($args);
    //wp_reset_postdata();
    //query_posts($myquery);
    if ($loop->have_posts()){
    //while ( have_posts() ) : the_post();
    while ( $loop->have_posts() ) : $loop->the_post();
    // output
  //        the_post();
    $loop->the_post();
    mystique_post();
    endwhile;
    //mystique_pagenavi();
    if ( function_exists( \'wp_pagenavi\' ) ) {
        wp_pagenavi( array( \'query\' => $loop ) );
        wp_reset_postdata();
    }

    }

SO网友:Reza Mamun

这可能有助于:

    ........
    ........
    if(isset($_POST[\'genre\'])) {
        $myquery = array(
            \'showposts\' => 20 ,
            \'orderby\' => \'title\',
            \'order\' => \'ASC\',
            \'paged\' => $paged,
            \'tax_query\' => array(
                \'relation\' => \'AND\',
                array(
                    \'taxonomy\' => \'anime_genre\',
                    \'terms\' => $_POST[\'genre\'],
                    \'field\' => \'slug\',
                    \'operator\' =>\'AND\'
                )
            )
        );
    }
    query_posts($myquery);
    ......

结束

相关推荐

Pagination on 2nd loop

好的,我正在创建一个业务列表网站,该网站使用列表“类型”的自定义分类法。我需要在分类法归档页面上显示两个循环,一个用于“赞助”列表,另一个用于常规列表。分类法存档:http://pastie.org/3187162分页功能:http://pastie.org/3187168这两部分都在做我想做的事情,但有一个问题:在一个特定类别中大约有50个非赞助商列表,但第二个查询最多有5个“页面”(即,如果我将posts\\u per\\u page设置为5,则有25个列表,如果我将posts\\u per\\u p