我使用这段代码来排除single.php文件中的日期,以阻止我放置在类别1中的任何帖子。我还需要添加157类,但是我所尝试的似乎都不起作用。
这是排除一个类别的代码:
<?php if ( !in_category (1)) { ?>
<div class="postdate"><?php the_time('F jS, Y') ?></div>
我也试过这些,但这些都不起作用:
<?php if ( !in_category (1,157)) { ?>
<div class="postdate"><?php the_time('F jS, Y') ?></div>
<?php if ( !in_category ('1','157')) { ?>
<div class="postdate"><?php the_time('F jS, Y') ?></div>
谁能告诉我我做错了什么?
如果要定义多个类别id,则需要将其强制转换为数组。在第三个代码片段中,您实际上传递了类别id 1作为函数的第一个参数,157作为函数的第二个参数。你的代码应该是:
<?php if (!in_category(array(1,157))) { ?>
如果你的文章是(或不是)在类别1或157。
try this:
in_category (array(1,157))
如果在这个函数中使用了多个参数,你应该使用数组方法来实现这个函数。