0

为了检查帖子ID是否存在,我这样做:

if ('publish' == get_post_status ($post_id)) {
    // do something
}

但是我如何检查 id 是否与 php 中的不同:

if ($id != $var) {
    //do stuff
}

我在做什么 :

$post_id = get_the_ID();
if ($post_id != 835) {
    //do stuff
}

这是对的吗 ?

4

1 回答 1

1

那么使用以下任何一种方法都应该适合您。如果当前帖子 ID不是8,则打印出“Not post 8”。如果要打印其他内容,可以添加 else 语句。

<?php
    $post_id = get_the_ID();
    if ($post_id != "8") {
        echo "Not post 8";
    }
?>

<?php
    $post_id = get_the_ID();
    if ($post_id != 8) {
        echo "Not post 8";
    }
?>
于 2014-03-27T00:02:03.207 回答