2016-11-22 32 views
0
<?php while (have_posts()) : the_post(); ?> 
    <section class="panel panel-white"> 
     <div class="row single-post-content"> 
      <?php if ($category_name !== 'Jobs') { ?> 
       <h5 class="author-post__title"><?php the_author() ?></h5> 
       <p><?php echo get_the_date(); ?></p> 
      <?php } 

      the_content(); 

      if ($category_name !== 'Jobs') { ?> 
       <div class="row author-post"> 
        <div class="small-12 medium-4 column"> 
         <img src="<?php echo get_avatar(); ?>" alt="" /> 
        </div> 
        <div class="small-12 medium-8 column"> 
         <h5 class="author-post__title"><?php the_author() ?></h5> 
         <p> 
          Lorem Ipsum has been the industry's standard dummy text 
          ever since the 1500s, when an unknown printer took a 
          galley of type and scrambled it to make a type specimen 
          book. It has survived not only five centuries, but 
          also the leap into electronic typesetting, remaining 
          essentially unchanged. It was popularised in the 1960s 
          with the release of Letraset sheets containing. 
         </p> 
        </div> 
       </div> 
      <?php } ?> 
     </div> 
    </section> 
<?php endwhile;?> 

我试图通过撰写帖子的作者的头像。 我认为这会使这项工作,但它似乎并没有输出正确的网址,并给了我一个404图像。WordPress的 - 获取作者图片

其他人通过头像图像做了什么方法?

我正在寻找一个答案,告诉我如何做到这一点,如果没有图像不显示一个。

UPDATE:

我曾尝试使用下面的代码,使这项工作:我要指出,我试图让我的本地机器上的这项工作为好。

echo get_avatar($authorId, 100); 

(变量使用get_the_author_id()

+0

我已经添加了一个更新我的问题 –

回答

1

你需要添加参数“id_or_email”,以获取相应的化身。对于WordPress 2.7或更低版​​本,您可以使用get_the_author_id()。对于 WordPress 2.8及更高版本,您可以使用get_the_author_meta('ID')。该函数返回一个字符串或false布尔值。您可以比较返回值以确定您是否有任何头像。 - get_avatar

<?php while(have_posts()): ?> 
    <?php the_post(); ?> 
    <section class="panel panel-white"> 
     <div class="row single-post-content"> 
      <?php if($category_name !== 'Jobs'): ?> 
       <h5 class="author-post__title"> 
        <?php the_author() ?> 
       </h5> 
       <p><?php echo get_the_date(); ?></p> 

       <?php the_content(); ?> 

       <div class="row author-post"> 
        <div class="small-12 medium-4 column"> 
         <?php if($avatar = get_avatar(get_the_author_meta('ID')) !== FALSE): ?> 
          <img src="<?php echo $avatar; ?>" alt=""> 
         <?php else: ?> 
          <img src="/images/no-image-default.jpg"> 
         <?php endif; ?> 
        </div> 
        <div class="small-12 medium-8 column"> 
         <h5 class="author-post__title"><?php the_author() ?></h5> 
         <p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing.</p> 
        </div> 
       </div> 
      <?php else: ?> 
       <?php the_content(); ?> 
      <?php endif; ?> 
     </div> 
    </section> 
<?php endwhile; ?> 
+0

这似乎不适用于我:/ –

+0

什么字符串从get_avatar()返回? – Daerik

+0

该死的我得到这个:Warning:缺少get_avatar()的参数1,在第68行调用F:\ xampp \ htdocs \ vallum \ wp-content \ themes \ vallum \ single.php并在F:\ xampp \ htdocs中定义\ vallum \ wp-includes \ pluggable.php 2266行 –

0
<?php echo get_avatar($id_or_email, $size, $default, $alt, $args); ?> 

在需要id_or_email。你的代码中缺少这个。欲了解更多https://codex.wordpress.org/Function_Reference/get_avatar

因此,在你的代码,试图让笔者图片:

<?php echo get_avatar(get_the_author_meta('ID'), 32); ?> 
+0

谢谢,但我已经试过这样:echo get_avatar($ AUTHORID,100);和变量使用get_the_author_id() –

+0

任何想法为什么上述不工作?我应该提到,id返回2 –