我正在尝试通过他们的分类法获取所有自定义帖子,然后将前两个税收放在一列中,其余的放在第二列中。但我的代码循环一切,我得到多个div。想法?
这是我的代码:
<div class="row">
<?php
$post_type = 'myposttype';
$tax = 'mytaxonomy';
$tax_terms = get_terms($tax,'hide_empty=0');
if ($tax_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
?>
<div class="column1">
<?php
if( $my_query->have_posts() ) {
if( ($tax_term->name == 'first_taxterm') || ($tax_term->name == 'second_taxterm') ) {
echo "<h2 class=\"tax_term-heading\" id=\"".$tax_term->slug."\"> $tax_term->name </h2>";
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} else {?>
</div>
<div class="column2">
<?php
echo "<h2 class=\"tax_term-heading\" id=\"".$tax_term->slug."\"> $tax_term->name </h2>";
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile; }?>
</div><?php
}
wp_reset_query();
}
}
?>
-
答案 0 :(得分:0)
尝试根据您的$ tax
来削减您的wp_query答案 1 :(得分:0)
没办法,所以我像这样使用多个查询...
<?php
$args=array(
'trend-categories' => 'flowers',
'post_type' => 'trend',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<h2> TITLE BIG </h2><ul>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a class="hey" href="<?php the_permalink() ?>" rel="bookmark" <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
}
wp_reset_query();
?>
</ul>