Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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 头像显示Wordpress_Php_Wordpress - Fatal编程技术网

Php 头像显示Wordpress

Php 头像显示Wordpress,php,wordpress,Php,Wordpress,我试图在我的wordpress主题上显示一个图像,这取决于哪个作者写了这个页面 因此,我正在这样做: <img src="<?php $autor=the_author_meta('display_name'); if (strpos($autor,'foo') !== false) {echo esc_url(get_template_directory_uri() ); ?>/bilder/foo.jpg" /> <?php } else {echo es

我试图在我的wordpress主题上显示一个图像,这取决于哪个作者写了这个页面

因此,我正在这样做:

<img src="<?php $autor=the_author_meta('display_name'); 
if (strpos($autor,'foo') !== false) 
{echo esc_url(get_template_directory_uri() ); ?>/bilder/foo.jpg" />
<?php } else  {echo esc_url( get_template_directory_uri() ); }
        ?>/bilder/fun.jpg" />
我做错了什么?因此,我不想使用插件-但谢谢;)

将\u author\u meta()
设置为输出结果,您只需返回结果即可。因此,将其改为
获取\u作者\u meta()

我还整理了你的代码,因为我认为其中有一些错误

<img src="<?php $autor = get_the_author_meta('display_name'); 
if (strpos($autor,'foo') !== false) {
    echo esc_url(get_template_directory_uri())."/bilder/foo.jpg";
} else {
    echo esc_url(get_template_directory_uri())."/bilder/fun.jpg";
} ?>" />
“/>
当我用我的用户名替换
foo
时,图像路径显示为/bilder/foo.jpg,当我将其更改回任何不是我的用户名的内容时,它显示为/bilder/fun.jpg,因此我相信它可以正常工作。模板URL也可以正常显示

<img src="<?php $autor = get_the_author_meta('display_name'); 
if (strpos($autor,'foo') !== false) {
    echo esc_url(get_template_directory_uri())."/bilder/foo.jpg";
} else {
    echo esc_url(get_template_directory_uri())."/bilder/fun.jpg";
} ?>" />