以下内容正在努力从Wordpress的特定类别帖子中排除作者的姓名。我还想排除某些作者(用户)的名字出现在帖子中。如何扩展此代码以执行此操作?
<?php if ( !in_category('10') ) { ?>
by <?php the_author(); ?>
<?php } ?>
我在下面尝试了这个,并收到了一个意外的else错误:
<?php if ( !in_category('10') )
else (!user_id('7') )
{ ?>
by <?php the_author(); ?>
<?php } ?>
如果您希望它排除类别 10 和用户 7 的情况:
<?php if ( !in_category('10') && !user_id('7') ) { ?>
by <?php the_author(); ?>
<?php } ?>
如果要排除类别 10 或用户 7:
<?php if ( !in_category('10') || !user_id('7') ) { ?>
by <?php the_author(); ?>
<?php } ?>
编辑:根据评论,看起来user_id()
不是您实际需要的功能。看起来你可能想要这个:
<?php if (!in_category('10') || get_the_author_meta('ID')=='7' ) { ?>
by <?php the_author(); ?>
<?php } ?>
使用一个 if 语句和 &&(AND) 运算符:
<?php if ( !in_category('10') && !user_id('7') ) { ?>
by <?php the_author();
} ?>