Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何添加从php字符串中排除用户名的条件_Php_Wordpress - Fatal编程技术网

如何添加从php字符串中排除用户名的条件

如何添加从php字符串中排除用户名的条件,php,wordpress,Php,Wordpress,以下是从Wordpress中特定类别的帖子中排除作者姓名的工作。我还想排除某些作者(用户)的名字出现在帖子上。如何扩展此代码以实现此目的 <?php if ( !in_category('10') ) { ?> by <?php the_author(); ?> <?php } ?> 通过 我在下面尝试了此操作,但收到意外的else错误: <?php if ( !in_category('10') ) else (!user_id('7') )

以下是从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 } ?>

通过

使用一个if语句和&&(and)运算符:

<?php if ( !in_category('10') && !user_id('7') ) { ?>
    by <?php the_author(); 
} ?>

通过

如果要排除类别10和用户7:

<?php if ( !in_category('10') && !user_id('7') ) { ?>
by <?php the_author(); ?>
<?php } ?>

if/else语句的语法不正确。PHP将else块视为在if语句中,而不是对它的补充。您需要在第一个if语句之后添加一行或一些空括号(通常,逻辑语句后跟空括号意味着您应该重新考虑逻辑)。对不起,关于空括号语句的逻辑,您是什么意思?嘿,这意味着您做了
if(condition)else(condition){statement}
当它应该是
if(condition){statement}else(condition){statement}
时,但这不是您真正想要的anyways@Chris当前位置我指的是蜡笔所描述的。我把它作为一个评论,因为它没有回答你的问题,但它的语法不正确。第一个有效,但第二个让我知道“致命错误:调用未定义的函数post_author”用户id在这里使用的术语是错误的吗?@Chris我不知道,可能吧。我不知道wordpress的功能;我只是简单地向您展示了调用函数的正确语法,我假设您已经完成了。我确实想让第二个函数开始工作,因为我需要排除特定类别或特定用户。@Chris如果我不得不猜测的话,我会认为它可能更像
author\u id()
author\u id()
或者甚至可能是
作者()的一个参数,例如
作者('id')
,但我只是在这里猜测。您应该阅读Wordpress提供的任何文档,了解它们是如何公开它的。感谢您在语法方面的帮助,问题肯定是user_id函数。
<?php if ( !in_category('10') || !user_id('7') ) { ?>
by <?php the_author(); ?>
<?php } ?>
<?php if (!in_category('10') || get_the_author_meta('ID')=='7' ) { ?>
by <?php the_author(); ?>
<?php } ?>