嗨,我正在尝试使用if语句。
如果帖子是由特定作者创建的,我想显示一些HTML代码。
这就是我想到的,但它不起作用。
<?php if ( get_posts ($post->ID, \'post_author\', true) == \'20\')
{ ?> HTML <?php } ?>
谢谢你嗨,我正在尝试使用if语句。
如果帖子是由特定作者创建的,我想显示一些HTML代码。
这就是我想到的,但它不起作用。
<?php if ( get_posts ($post->ID, \'post_author\', true) == \'20\')
{ ?> HTML <?php } ?>
谢谢你这个get_posts()
函数从数据库中检索帖子。如果我理解正确,那不是你想要的,你只是想查看当前显示的帖子的作者。
您可以简单地使用$post->post_author
. 如果在外部the Loop, 你必须拜访$post
全球第一。
因此
global $post; // only required outside the loop
if ( 20 === $post->post_author ) {
// do stuff
}
会做你想做的事。假设你在循环中,你可以使用get_the_author()
, 返回作者Display Name:
if ( \'Author Display Name\' == get_the_author() ) {
// This post is written by the
// specified author; do something
}
请注意get_the_author()
不接受任何参数,因此必须从循环内部使用。每当用户按评论作者时,它都会将用户重定向到用户浏览的站点。我只想添加target=“\\u blank”元素。我可以在哪里修改它?在文件中,我只看到以下内容:get\\u comment\\u author\\u link()