我尝试使用下面的代码的输出是一个日期大于或等于今天的日期的事件列表:设置循环之前在循环外设置变量的最佳方法是什么?
$args = array('post_type' => 'event') // setup my custom post type
$todaysdate = blah blah //setup for today's date
// the wp loop
query_posts($args);
if ((have_posts() && $eventdate >= $todaysdate) ) : while (have_posts()) : the_post();
$eventdate = blah blah // setup for the date of the event;
echo $event;
endwhile; endif;
正如你所看到的问题是,如果依赖于在循环内的变量。
首先在循环外设置变量的最佳方法是什么?
为什么不直接运行while循环并将if语句移到while循环中? – Jonast92 2013-03-26 16:24:46