我试图将广告商分为三类(自定义分类法“ad\\U类别”),即基本类、休闲类和高级类。作为默认查询,一个页面包含10个结果,但它应该在顶部显示高级广告商,然后是临时广告商和基本广告商。
如果我总共有30个高级和休闲广告,基本广告从第4页开始。
我的代码是:
loop-suppliers-basic.php
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$title = get_term_by(\'slug\', get_query_var(\'term\'), get_query_var(\'taxonomy\') );
$args = array(
\'post_type\' => \'suppliers\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'ad_category\',
\'field\' => \'slug\',
\'terms\' => array(\'basic_advertiser\'),
),
array(
\'taxonomy\' => \'supplier_categories\',
\'field\' => \'slug\',
\'terms\' => $title->slug,
),
),
\'paged\' => $paged,
\'orderby\' => \'rand\'
);
$the_query = new WP_Query( $args ); ?>
<?php if ($the_query->have_posts()) : while($the_query->have_posts()) : $the_query->the_post(); ?>
////////// Loop goes here /////////
<?php endwhile; endif; ?>
taxonomy-supplier_categories.php
<?php get_template_part(\'loop-suppliers-premium\'); ?>
<?php get_template_part(\'loop-suppliers-casual\'); ?>
<?php get_template_part(\'loop-suppliers-basic\'); ?>
<?php get_template_part(\'pagination\'); ?>
Pagination function
function wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
\'base\' => str_replace($big, \'%#%\', get_pagenum_link($big)),
\'format\' => \'?paged=%#%\',
\'current\' => max(1, get_query_var(\'paged\')),
\'total\' => $wp_query->max_num_pages
));
}
这确实按我想要的顺序显示,但分页出错。尝试使用**rewind\\u posts()等方法*但没有起作用。
SO网友:NikHiL Gadhiya
立即尝试此代码
<?php
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$title = get_term_by(\'slug\', get_query_var(\'term\'), get_query_var(\'taxonomy\') );
$args = array(
\'post_type\' => \'suppliers\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'ad_category\',
\'field\' => \'slug\',
\'terms\' => array(\'basic_advertiser\'),
),
array(
\'taxonomy\' => \'supplier_categories\',
\'field\' => \'slug\',
\'terms\' => $title->slug,
),
),
\'paged\' => $paged,
\'orderby\' => \'rand\'
);
$the_query = new WP_Query( $args ); ?>
<?php if ($the_query->have_posts()) : while($the_query->have_posts()) : $the_query->the_post(); ?>
////////// Loop goes here /////////
<?php endwhile; ?>
<nav class="pagination">
<?php pagination_bar( $the_query ); ?>
</nav>
<?php wp_reset_postdata();
endif;
function wp_pagination($wp_query)
{
$big = 999999999;
echo paginate_links(array(
\'base\' => str_replace($big, \'%#%\', get_pagenum_link($big)),
\'format\' => \'?paged=%#%\',
\'current\' => max(1, get_query_var(\'paged\')),
\'total\' => $wp_query->max_num_pages
));
}