我在使以下代码在我的 wordpress 侧栏中工作时遇到了一些问题:
$the_query = get_posts( $args );
$year_post = 0;
foreach ($the_query as $post) :
setup_postdata($post);
$current_year = get_the_time('Y');
if( $current_year != $year_post ) {
$year_post = $current_year;
echo '<li><a href="'.get_year_link($current_year).'">'.$current_year.'</a></li>';
}
$month_post = 0;
foreach ($post as $post_monthly) :
setup_postdata($post_monthly);
$current_month = get_the_time('m');
if ($current_month != $month_post){
$month_post =$current_month;
echo '<li><a href="'.get_year_link($current_month).'">'.$current_month.'</a></li>';
}
foreach ($post_monthly as $post_title) :
setup_postdata($post_title);
echo '<li><a href="'.get_permalink().'">'.the_title().'</a></li>';
endforeach;
endforeach;
endforeach;
wp_reset_postdata();
使用此代码,我试图显示以下内容:
- 2012年
-5月- Lorem ipsum
- Lorem ipsum
- Lorem ipsum
它显示 2012 年 5 月,但在显示帖子标题时出现以下错误:“警告:为 foreach() 提供的参数无效”
我已经检查了很多次这个代码,我似乎没有看到问题。
任何人都可以看到我缺少的东西,将不胜感激。谢谢!