问题与标题相同。我说的是博客页面/主页上的默认循环。
我正在使用网络博客,必须将其应用于所有博客。
问题与标题相同。我说的是博客页面/主页上的默认循环。
我正在使用网络博客,必须将其应用于所有博客。
你还是要利用pre_get_posts
在主查询实际运行之前更改主查询查询变量。博客页面/主页可以通过is_home()
条件标记
add_action( \'pre_get_posts\', function ( $q )
{
if ( is_home() // Only targets the home/blog page
&& $q->is_main_query() // Only targets the main query
) {
// Works on build in taxonomy category, for custom taxonomies, use a tax_query
$q->set( \'cat\', -1 ); // Change with correct category ID, minus sign means remove
}
}, PHP_MAX_INT ):
我会将其添加到一个插件中,您可以作为network plugin across the entire network我需要每两篇文章显示一个不同的布局,是否可以使用偶数/奇数来实现这一点?<?php while (have_posts()): the_post() ?> <?php if ($wp_query->current_post % 2 == 0): ?> even <?php else: ?> odd <?php endif ?> <?php endwhile