如何计算条件语句的输出


How to count the output of a conditional statement?

我正在计算我的wordpress站点上有多少篇文章的时间戳大于或等于今天。

我将当前时间和post时间戳放入两个变量中,并猜测它将开始:

if ($timestamp >= $curent_time) {

也包括countthe_post()

但是我被卡住了。我想不出怎么把它拼起来。什么好主意吗?

您应该对posts进行某种循环,然后在条件中增加计数器,例如:

$curent_time = date('d-m-Y'); //or whatever format date
$cont = 0;
//for each post
foreach($posts as $post){
    $timestamp = $post['timestamp'] // or whatever
    if ($timestamp >= $curent_time) {
        $cont++;
    }
}
echo $cont;