Wordpress循环分类法php文件CPT按分类法筛选
我在wordpress上的taxonomy.php文件中有一个自定义的post类型循环,运行良好Wordpress循环分类法php文件CPT按分类法筛选,php,wordpress,loops,custom-post-type,Php,Wordpress,Loops,Custom Post Type,我在wordpress上的taxonomy.php文件中有一个自定义的post类型循环,运行良好 <div class="container"> <?php $i = 1; //added before to ensure it gets opened echo '<div class="row">'; $wp_query = new WP_Query(array('post_type' => 'publica', 'p
<div class="container">
<?php
$i = 1;
//added before to ensure it gets opened
echo '<div class="row">';
$wp_query = new WP_Query(array('post_type' => 'publica', 'posts_per_page' => 6));
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
// post stuff...
?>
<div class="col s12 m4">
<div class="notboxes">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium', array('class' => 'responsive-img')); ?></a>
<?php get_the_term_list($id, $taxonomy, $before, $sep, $after) ?>
<span class="litletimebox"><?php the_time('H:i'); ?> | <?php echo get_the_term_list($post->ID, 'comision-publicaciones') ?></span>
<a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
<p><?php echo get_the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>" class="waves-effect waves-light btn abbutton amber lighten-1">Leer Más</a>
</div>
</div>
<?php
// if multiple of 3 close div and open a new div
if ($i % 3 == 0)
{
echo '<div style="clear:both"></div></div><div class="row">';
}
$i++;
endwhile;
endif;
//make sure open div is closed
echo '</div>';
?>
</div>
但是当我使用cat=$teru id
来过滤分类法时
$wp_query = new WP_Query( array( 'post_type' => 'publica', 'posts_per_page' => 6, 'cat' => $ter_id));
它不会加载到页面上
所以我一直在网络上搜索,我发现了一个循环,它通过它的帖子拉取所有分类法
<?php
$custom_terms = get_terms('comision-publicaciones');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'publica',
'tax_query' => array(
array(
'taxonomy' => 'comision-publicaciones',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
while($loop->have_posts()) : $loop->the_post(); ?>
<a href=""><?php echo get_the_title(); ?></a>
<?php endwhile;
}
}
?>
这在我的需要中非常有效,但只需要来自分类页面im上的帖子,例如http://comisionpais.com/comision-publicaciones/salud/
仅加载标有“salud”标记的立柱
此图显示了所有循环为什么我要粘贴第一个代码和最后一个代码,如果它能在某些方面有所帮助的话
<?php
$custom_terms = get_terms('comision-publicaciones');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'publica',
'tax_query' => array(
array(
'taxonomy' => 'comision-publicaciones',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
while($loop->have_posts()) : $loop->the_post(); ?>
<a href=""><?php echo get_the_title(); ?></a>
<?php endwhile;
}
}
?>