类别中自定义帖子类型的分页。php为/page/2返回404页。如果我转到/page/1,它会重定向并正常工作,但/page/2会中断。
永久链接设置为/%postname%/
我已经尝试了在google上看到的所有修复,但都没有效果
<?php
get_header(); ?>
<div class="home-gradient">
<div id="container">
<?php include(\'snippet-post-gallery.php\'); ?>
<div class="content-wrap">
<?php
$catID = get_query_var(\'cat\');
$catName = strtolower(get_cat_name($catID));
$myquery = new WP_Query(array(
\'post_type\' => \'any\',
\'paged\' => $paged,
\'posts_per_page\' => 1,
\'category_name\' => $catName)
);
while ( $myquery->have_posts() ) : $myquery->the_post();
$img_id = get_post_meta($post->ID,\'main_image\',true);
$img_url = wp_get_attachment_url($img_id);
?>
<div class="post-box">
.............
</div>
<?php
endwhile;
wp_pagenavi( array( \'query\' => $myquery ) );
?>
<?php ?>
</div>
<div class="sidebar-wrap">
<?php get_sidebar(); ?>
</div>
<br class="clear">
</div>
</div>
<?php get_footer(); ?>
最合适的回答,由SO网友:Tallboy 整理而成
function category_set_post_types( $query ){
if( $query->is_category ):
$query->set( \'post_type\', \'any\' );
endif;
return $query;
}
add_action( \'pre_get_posts\', \'category_set_post_types\' );
This worked!