2014-09-12 35 views
-5

我正在学习WordPress主题开发,并且我开发了一个主题。所有的工作已经完成,但作者的名字不会显示在博客页面中。我使用以下内容:为什么the_author()不工作

<?php the_author(); ?> 

但它不工作。是否有必要在functions.php中执行任何函数或代码?

+1

您没有在该帖子中显示任何代码? – Howli 2014-09-12 14:48:42

+0

我们可以用一些代码来做... – Mike 2014-09-12 14:49:53

+0

<?php the_author(); ?> – 2014-09-12 14:49:53

回答

0

基本上,这是一个页面的WordPress的循环:

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

    some wordrpess code 

<?php endif; ?> 

您必须输入get请求进入死循环,这样的事情:

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

    <?php $author = get_the_author(); ?> 
    or 
    <?php the_author(); ?> 

<?php endif; ?> 
-2

如果不是在循环中你可以试试这个

<?php the_author_meta('display_name', $userID); ?> 

Codex