Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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
作者没有';无法在single.php中显示_Php_Wordpress_Author - Fatal编程技术网

作者没有';无法在single.php中显示

作者没有';无法在single.php中显示,php,wordpress,author,Php,Wordpress,Author,我正在创建一个主题,我无法在single.php页面上显示作者。它在网站的下方显示,但在标题下的第一次通话中似乎没有显示 <header class="intro-header" style="background-image: url('http://i.imgur.com/ZyZMhQv.jpg')"> <div class="container"> <div class="row"> <div cla

我正在创建一个主题,我无法在single.php页面上显示作者。它在网站的下方显示,但在标题下的第一次通话中似乎没有显示

<header class="intro-header" style="background-image: url('http://i.imgur.com/ZyZMhQv.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="site-heading">
                    <h1><?php the_title(); ?></h1>
                    <hr class="small">
                    <span class="subheading">Posted by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?></span>
                    <div id="avatar" class="row text-center"><?php echo get_avatar( $post->post_author, 92 ); ?> </div>
                </div>
            </div>
        </div>
    </div>
</header>


寄于
第二次在循环中调用时,它工作正常

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="panel panel-default panel-body">

        <?php while(have_posts()) : the_post(); ?>
            <p> Posted by <?php the_author(); ?> on <?php the_time('F jS, Y'); ?> </p>
            <p> <?php the_content(''); ?> </p>
            <?php endwhile; wp_reset_query(); ?>
        </div>
    </div>

寄于


为什么它在第一次调用时不显示?

根据-它必须在循环中。

我不是WP专家,但使用
呼应作者()有什么区别
echo$post->post\u作者?如果我必须猜测,那么
作者()
仅在循环
have\u posts()
时返回,我不确定这是否有效,请尝试-作者(获取\u ID());可以这是否意味着无法在循环外显示它?这是正确的。我建议在代码中更早地开始循环。我刚刚做了,它工作得很好。谢谢你的意见。