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()に無効な引数が指定されました」
このコードを何度もチェックしましたが、問題が発生していないようです。
私が見逃しているものを誰かが見ることができますか、それは高く評価されます。ありがとう!