如果为Else,则为自定义$curauth->字段

时间:2013-03-12 作者:Chozen

因此,我在作者页面上有一个自定义字段,用户在其中上载一个图像,该图像将用作其作者页面上的背景图像。我已经设置好了所有内容,但我不知道如何设置条件,以便在用户没有上传自己的图像时显示默认图像。

自定义$curauth->字段称为user\\u banner。

所以基本上:

[如果user\\u横幅]

图像将显示在此处。

[其他]

默认图像将显示在此处。

[结束]

有什么想法吗?

1 个回复
SO网友:chrisguitarguy

组合get_queried_object_id 获取当前用户ID和get_user_meta 要检索横幅,就应该这样做。

<?php
// somewhere in your theme\'s author.php

if ($img = get_user_meta(get_queried_object_id(), \'user_banner\', true)) {
   // they uploaded an image, use it
} else {
   // they did not upload the image, show the default
}

结束

相关推荐

Refine custom posts by author

我想有一种为特定作者显示自定义后期存档的方法。我能够显示某个类别的自定义帖子,但不仅仅是作者的自定义帖子。我已经有了一个单独的作者页面模板,显示他们写的所有帖子,按帖子类型划分。我使用以下方式查询此信息:query_posts( array( \'post_type\' => \'custom_post_name\', \'author\'=>$curauth->ID ) ); while (have_p