2013-12-09 23 views
1

我是新来的PHP。如何添加作者图片和说明 - WordPress的

我使用作者图像小部件。 http://www.semiologic.com/software/author-image/

我使用下面的简单代码来获取作者图像。

author.php: $auth_foto = the_author_image($authorid); echo $auth_foto;

它的正常工作。它展示了作者的形象。

现在我想在图像下方显示作者描述和他的帖子标题? 我该怎么做?我试过<?php the_author_meta('description'); ?> 但它不起作用。

在此先感谢。

解决方案 它现在工作正常,当我使用下面的代码。

` 
$author_id=$post->post_author; 

$auth_foto = the_author_image($author_id); 

function auth_desc ($author_id) { 
echo the_author_meta('display_name', $author_id).'<br/>'; 
echo get_the_author_meta('user_email', $author_id).'<br/>';     
echo the_author_meta('description', $author_id).'<br/>'.'<br/>'.'<br/>'; 
} 

echo $auth_foto; auth_desc($author_id); ` 

回答

2

与ID这样的标签工作:

<?php the_author_meta($field, $userID); ?> 

详细here

根据你的代码,你可以尝试这样的:

<?php $auth_foto = the_author_image($authorid); 
$userId = 1; 
function auth_desc ($userId) { 
    echo get_the_author_meta('user_email', $userId); 
    echo the_author_meta('display_name', $userId); 
echo the_author_meta('description', $userId); } 
echo $auth_foto; auth_desc($userId); ?> 

在上面的代码分配动态值$userID

+0

感谢您的.. 我有一个看的.. 问题是下面的代码不打印作者详细.. 但它的打印笔者图像.. '\t \t \t \t <?PHP \t \t \t \t \t \t $ auth_foto = the_author_image($ AUTHORID); \t \t \t $ auth_detail = the_author_meta('description',$ authorid); \t \t \t echo $ auth_foto; \t \t \t echo $ auth_detail; \t \t \t \t \t \t \t \t?> \t \t' 什么想法? –

+0

此方法直接将输出发送到browser.you不能像你这样将它分配给变量。试试这样<?php the_author_meta('user_email',25); ?>< –

+0

感谢对于.. 现在下面的代码工作.. '' 但我有2位作者..这些细节应该在他们的页面下自动显示。所以作者ID必须自动分配..不是吗? 但现在所有的细节都属于用户标识1。 因此,如何更改它自动分配作者或用户ID? –

1

如果您使用The Loop之外的功能,则需要添加作者ID。

<?php the_author_meta('description', $authorid); ?> 

旁注:一些主题(尤其是默认的主题)自动显示作者的姓名,照片和说明,当博客有一个以上的用户。

+0

感谢的.. 我已经试过了.. 但没有工作.. '' 它不打印$ auth_detail?; 有什么建议吗? –

+0

'the_author_meta()'不返回任何东西,它直接输出内容。如果你想存储描述以备后用,你必须使用'get_the_author_meta()'(用法相同)。根据您调用'the_author_meta()'的位置,输出可能会被抑制。 –

+0

感谢您的解释.. 我不知道我使用正确的代码,因为我的PHP知识。 ? '' 仍然$$ auth_detail?;不被打印 是那个正确的代码? –

相关问题