编辑注:您可以对自定义页面模板使用相同的技术,通过new WP_Query()
:
// Post Formats
$post_formats_array = array(
\'post-format-aside\',
\'post-format-audio\',
\'post-format-chat\',
\'post-format-gallery\',
\'post-format-image\',
\'post-format-link\',
\'post-format-status\',
\'post-format-quote\',
\'post-format-video\'
);
// Custom query args
$standard_posts_query_args = array(
\'tax_query\' => array(
array(
\'taxonomy\' => \'post_format\',
\'field\' => \'slug\',
// Use array defined above,
// or try omitting \'terms\' entirely
\'terms\' => $post_formats_array,
\'operator\' => \'NOT IN\'
)
)
);
// Custom query
$standard_posts = new WP_Query( $standard_posts_query_args );
// Custom query loop
if ( $standard_posts->have_posts() ) : while ( $standard_posts->have_posts() ) : $standard_posts->the_post();
// Loop markup here
endwhile; endif;
分页对于分页,
please refer to this Question/Answer.
原始答案
为什么不将具有帖子格式的帖子从主帖子存档中排除?
function wpse129372_filter_posts_archive( $query ) {
if ( $query->is_main_query && $query->is_archive() ) {
$post_formats_array = array(
\'post-format-aside\',
\'post-format-audio\',
\'post-format-chat\',
\'post-format-gallery\',
\'post-format-image\',
\'post-format-link\',
\'post-format-status\',
\'post-format-quote\',
\'post-format-video\'
);
$tax_query = array(
array(
\'taxonomy\' => \'post_format\',
\'field\' => \'slug\',
// Use array defined above,
// or try omitting \'terms\' entirely
\'terms\' => $post_formats_array,
\'operator\' => \'NOT IN\'
)
);
$query->set( \'tax_query\', $tax_query );
}
}
add_action( \'pre_get_posts\', \'wpse129372_filter_posts_archive\' );
这与(我假设)自定义模板文件(或自定义页面模板)一起用于具有帖子格式的帖子,将是一种在归档索引中仅显示“标准”帖子的非常简单的方法。