這是一些基本的IF THEN聲明的東西,但我是一個編碼新手,所以我希望有人可以扔我骨頭:-)。如何返回單個結果,如果所有帖子在循環匹配條件
我有幾個職位有自定義日期字段。我想:
1)遍歷所有這些帖子,並評估每個帖子的日期字段是否過去。如果是這樣,我想顯示特殊消息。
2)如果只是其中一個帖子在過去,我想繼續評估,直到查詢中所有帖子的末尾都到達。 3)如果發現即使有一個日期爲將來的帖子,我也會從該帖子中顯示更多內容,而不是專用帖子。
當前,特殊消息僅當循環中的項目根本沒有發佈內容時才顯示。在評估每篇文章之後,我也能夠得到它,但之後我對每篇評論文章都收到了特別留言,我甚至希望即使在任何一個帖子的任何一個帖子都會返回true。
我當前的代碼是這樣的:
<?php
$parent = get_cat_name($category[0]->category_parent);
$cur_cat = $cur_cat_slug;
$cur_date = current_time('timestamp',0);
echo $cur_cat_name;
?>
</div>
<div class=dates>
<?php
$categoryvariable=$category; // assign the variable as current category
$query= 'cat=' . $cur_cat_id. '&posts_per_page=100&meta_key=date_value&orderby=meta_value&order=ASC&meta_compare=>=&meta_value=$cur_date'; // concatenate the query
query_posts($query); // run the query
if (have_posts()) : while (have_posts()) : the_post();
$date_value = get_post_meta($post->ID, 'date_value', true);
if ($date_value>=$cur_date)
{
?>
<a class=dates-link href="<?php the_permalink(); ?>">
<li><?php echo date("D, n/j/Y, g:ia", get_post_meta($post->ID, 'date_value', true)); ?> - <?php $key="course_endtime"; echo get_post_meta($post->ID, $key, true); ?>
</a>
<div class=info>
<table cellpadding=0 cellspacing=3 border=0>
<tr>
<td valign=top><img src="<?php bloginfo('template_directory'); ?>/images/i.jpg"></td>
<td>Click any date for more info about a course and to register online.</td>
</tr>
</table>
</div>
<?php
}
endwhile; else:
?>
<div class=course-content>Sorry, no courses are currently scheduled. See <a href="http://dynamictactical.org/courses/" style="color:#000000; text-decoration:underline;">Course Calendar</a> for all upcoming DTT courses.</div>
<? endif;
wp_reset_query();?>