我在我的另一个类似主题的网站上使用了这段代码。即使在管理仪表板中,所有设置都是相同的。但这个不起作用。所有内容均来自自定义帖子类型。我错过什么了吗?也许是更好的代码?
<?php
if ( get_query_var(\'paged\') ) {
$paged = get_query_var(\'paged\');
} elseif ( get_query_var(\'page\') ) {
$paged = get_query_var(\'page\');
} else {
$paged = 1;
}
$qobj = get_queried_object();
if ( !$qobj )
return;
else
$args = array(
\'post_type\' => array(\'portal\'),
\'orderby\' => \'id\',
\'posts_per_page\' => 1,
\'paged\' => $paged,
\'tax_query\' => array(
array(
\'taxonomy\' => $qobj->taxonomy,
\'field\' => \'slug\',
\'terms\' => $qobj->name
)
)
);
$random_query = new WP_Query( $args );
if ($random_query->have_posts()) :
while ($random_query->have_posts()) : $random_query->the_post();
?>
<?php //all content ?>
<?php endwhile; ?>
<?php endif; ?>
<div class="the-pagination">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\',
\'prev_text\' => __(\' Previous\'),
\'next_text\' => __(\'Next \'),
\'current\' => max( 1, get_query_var(\'paged\') ),
\'total\' => $random_query->max_num_pages
) );
?>
</div>
谢谢你的帮助!
最合适的回答,由SO网友:MightyGas 整理而成
别客气。我忘了在我的functions.php
. 我会把答案留在这里,这样可以帮助别人。
//Tag pagination pages
function wpd_custom_types_on_tag_archives( $query ){
if( $query->is_tag() && $query->is_main_query() ){
$query->set( \'post_type\', array( \'portal\' ) );
}
}
add_action( \'pre_get_posts\', \'wpd_custom_types_on_tag_archives\' );