我嘗試使用下面的代碼的輸出是一個日期大於或等於今天的日期的事件列表:設置循環之前在循環外設置變量的最佳方法是什麼?
$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