如何在循环中读取分类法?下面是更好地解释的代码:
<?php $term = get_term_by(\'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) );
$query = new WP_Query(array(
\'post_type\' => \'recipe\',
\'meta_key\' => \'recipe_star_rating\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
/// \'taxonomy\' => $term->slug,
));
$counter = 0;
global $wp_query;
$total_results = $query ->found_posts;
echo \'<h2>"\'.$term->name . \'" Recipes</h2>\';
echo \'<h4 class="tcount">\'. $total_results . \' results</h4>\'; ?>
<hr class="aloha" />
<?php while ($query->have_posts()): $query->the_post(); $counter++; ?>
<div class="col-md-12 col-sm-6 col-xs-12">
<?php echo Chefscuisine_Template_Loader::load( \'recipes/grid\' ); $counter++; ?>
</div>
<?php endwhile; ?>
<? if ($counter % 4 === 0) {
echo \'<div class="midad">Advert 336x280px Here!</div>\';
} ?>
所以我得到了清单,但并没有阅读困难-它可以是简单的,困难的,一般的。
SO网友:Djordje Milivojevic
我知道了,代码是:
...
<?php
$term = get_term_by(\'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ), get_queried_object()->term_id );
// $paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$query = new WP_Query(array(
\'post_type\' => \'recipe\',
\'meta_key\' => \'recipe_star_rating\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
// \'paged\' => $paged,
\'status\' => get_query_var( \'term\' ),
));
global $wp_query;
$total_results = $query ->found_posts;
echo \'<h2>"\'.$term->name . \'" Recipes</h2>\';
echo \'<h4 class="tcount">\'. $total_results . \' results</h4>\';
?>
<hr class="aloha" />
<?php $counter = 0; while ($query->have_posts()): $query->the_post(); $counter++; ?>
<div class="col-md-12 col-sm-6 col-xs-12">
<?php echo Chefscuisine_Template_Loader::load( \'recipes/grid\' ); // $counter++; ?>
</div>
<? if ($counter % 3 === 0) {
echo \'<div class="midad">Advert 336x280px Here!</div>\';
} ?>
<?php endwhile; ?>
</div>
...