我正在尝试显示posts 来自\'Uncategorized\' 名为\'Reviews\' 但运气不好。
我正在使用get_template_part(\'loop\',\'review\')
调用loop-review.php
其中包含我的分类循环,但由于某种原因,不会显示任何内容。有什么好处?
以下是loop-review.php
...
<div class="row no-margin detail">
<p class="title"><span>reviews</span></p>
<?php
$args = array(
\'post_type\' => \'post\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'review\',
\'field\' => \'slug\',
\'terms\' => \'uncategorized\'
)
)
); $review_query = new WP_Query($args); ?>
<?php if ($review_query->have_posts()): ?>
<?php while ($review_query->have_posts()): $review_query->the_post(); ?>
<p class="quote">
<?php the_content(); ?>
<span><?php the_title(); ?></span>
</p>
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
</div>
我打电话
get_template_part(\'loop\',\'review\')
在我的my内
category.php
...
<?php
get_header();
if (is_category(\'portfolio\')):
get_template_part(\'single\',\'portfolio\');
get_template_part(\'loop\',\'review\');
else:
get_template_part("single","blog");
endif;
get_footer();
?>
最后,这是我的
functions.php
...
add_action(\'init\', \'build_taxonomies\', 0);
function build_taxonomies(){
register_taxonomy(\'review\', \'post\', array(
\'hierarchical\' => \'true\',
\'label\' => \'Reviews\',
\'query_var\' => \'true\',
\'rewrite\' => \'true\'
)
);
}