在single.php中显示作者姓名(Wordpress)

Apa*_*dos 2 wordpress

我需要在Wordpress的single.php文件中显示帖子的作者.引用表明the_author(); 仅在循环内工作.

我一直在寻找其他论坛,没有找到.

任何的想法?

谢谢.

编辑:

    <div class="bar_info">
         <?php echo "By: ".the_author(); ?>
         <?php
                foreach((get_the_category()) as $category) { 
                    echo category->cat_name.', ';
                }
         ?>
    </div>
Run Code Online (Sandbox Code Playgroud)

Spe*_*rin 7

在你single.php,你很可能有一个电话the_post().你会发现WordPress 模板标签在这一行之后会正常工作.换句话说,你可以使用the_authorsingle.php.

编辑:根据您在问题中更新的代码,您需要在以下位置添加以下内容single.php:

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

此外,如果要在echo语句中使用作者姓名,请get_the_author改用.the_author实际上已经为你回声了.