//Display All Reviews
function display_all_reviews( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( \'tag\', \'reviews\' );
}
}
add_action( \'pre_get_posts\', \'display_all_reviews\' );
//Movie All Reviews
function display_movie_reviews( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( \'tag\', \'movie-reviews\' );
}
}
add_action( \'pre_get_posts\', \'display_movie_reviews\' );
Display All Reviews
是唯一应该显示在主页上的内容
display_movie_reviews
假设在其类别的侧栏中显示
is_category(\'movies\')
, 以及该类别的帖子。我看他们有
$query->is_home()
但我试过了
is_category(\'movies\')
没有任何运气。。
这是display_movies_reviews
类别的标记:
<div id="sidebar-reviews">
<span>Movie Reviews</span>
<ul>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php add_action( \'pre_get_posts\', \'display_movie_reviews\' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( \'sidebar-reviews\', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( \'no-results\', \'index\' ); ?>
<?php endif; ?>
</ul>
</div>
这是
display_movies_reviews
电影类别中帖子的标记:
<!-- ###Movies Single Sidebar### -->
<?php elseif ( ! empty ( $GLOBALS[\'post\'] ) && is_single() && in_category( \'movies\', $GLOBALS[\'post\'] ) ) : ?>
<div class="sidebar-ad">
</div>
<div id="sidebar-reviews">
<span>Movie Reviews</span>
<ul>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php add_action( \'pre_get_posts\', \'display_movie_reviews\' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( \'sidebar-reviews\', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( \'no-results\', \'index\' ); ?>
<?php endif; ?>
</ul>
</div>
我试过这样修理它:
//Movie All Reviews
function display_movie_reviews( $query ) {
if ( $query->is_category(\'movies\') ) {
$query->set( \'tag\', \'movie-reviews\' );
}
}
add_action( \'pre_get_posts\', \'display_movie_reviews\' );
但我一点运气都没有。有没有办法让主页和边栏正常工作?
edit: sidebar
<?php if ( $query->is_category(\'movies\') ): ?>
<?php $movies = new Wp_Query(\'tag=movie-reviews\'); ?>
<?php while ( $movies->have_posts() ) : ?>
<?php $movies->the_post(); ?>
<?php get_template_part( \'sidebar-reviews\', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( \'no-results\', \'index\' ); ?>
<?php endif; ?>