Php wordpress中的子循环
我在wordpress上有这样的帖子 “第一”类 2019年-职位1 2019年-职位2 2019年-第3期 2018年-邮政1 2018年-职位2 如何显示这样的内容 类别“第一” 2019年 职位1 职位2 邮政3 2018年 职位1 职位2 现在,这就是我的代码,它将给定类别的帖子呈现为“奇观”Php wordpress中的子循环,php,wordpress,Php,Wordpress,我在wordpress上有这样的帖子 “第一”类 2019年-职位1 2019年-职位2 2019年-第3期 2018年-邮政1 2018年-职位2 如何显示这样的内容 类别“第一” 2019年 职位1 职位2 邮政3 2018年 职位1 职位2 现在,这就是我的代码,它将给定类别的帖子呈现为“奇观” <?php $args = array( 'post_type'=> 'post',
<?php
$args = array(
'post_type'=> 'post',
'category_name'=>'spectacle',
'posts_per_page'=> -1
);
$specQuery = new WP_Query ($args);
while ($specQuery->have_posts()): $specQuery->the_post();
?>
<div class="row porfolio-details">
<div class="portfolio-image">
<?php echo the_post_thumbnail( 'full' ); ?>
<div class="caption">
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
</div>
</div>
<div class="portfolio-text">
<h6>
<?php the_content();?>
</h6>
</div>
</div>
<!--ENDS AND RESET THE LOOP-->
<?php endwhile; wp_reset_query(); ?>
因此,如何在类别上循环并通过另一个参数,并且该参数只显示一次?请将您的代码替换为:
<?php
$years = $wpdb->get_results( "SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY year DESC" );
foreach ( $years as $year ) {
echo '<h2>' . $year->year . '</h2><ul>';
$args = array(
'post_type'=> 'post',
'category_name'=>'spectacle',
'posts_per_page'=> -1
);
$specQuery = new WP_Query ($args);
while ($specQuery->have_posts()): $specQuery->the_post();
?>
<div class="row porfolio-details">
<div class="portfolio-image">
<?php echo the_post_thumbnail( 'full' ); ?>
<div class="caption">
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
</div>
</div>
<div class="portfolio-text">
<h6>
<?php the_content();?>
</h6>
</div>
</div>
<!--ENDS AND RESET THE LOOP-->
<?php endwhile; wp_reset_query(); ?>
<?php } ?>
它呈现每年的所有帖子。2018:post1、post2 2017:post1:post2。在我们看来,2017年似乎是一个次级阶段