基于作者姓名的Wordpress主题

时间:2012-01-08 13:52:05

标签: php wordpress

我正在尝试根据Wordpress中的帖子作者显示一些内容。这是我在循环中尝试的代码

<?php 
$author = the_author_meta('first_name');
echo $author;
if ($author == "Rabin" ) {
echo 'hi rabin';
}
else {
echo 'not Rabin';
}
?>

但不幸的是,这不起作用。每个页面/帖子都给出相同的结果。我把它放在这行之后

<?php if (have_posts()) : ?>    
<?php while (have_posts()) : the_post(); ?>

我已将echo $author;放置进行测试,它回显了作者的姓名,但其余的if else功能无效。

任何帮助都会很棒。提前谢谢..

1 个答案:

答案 0 :(得分:1)

使用“get_the_author_meta”而不是“the_author_meta”。

the_author_meta只会显示它,不能用于分配给变量: http://codex.wordpress.org/Function_Reference/get_the_author_meta

相关问题