简体   繁体   English

wordpress-在帖子图像顶部添加作者图片

[英]wordpress - add author picture on top of the post image

I am working in a custom theme in wordpress. 我正在使用wordpress中的自定义主题。 One of the pages "solutions_page", displays all the post with category "solutions", with it featured image, the title and some text. 页面“ solutions_page”之一显示所有类别为“ solutions”的帖子,并带有特色图片,标题和一些文本。

On top of the featured image, I need to add a circle with a picture of the author. 在精选图片的顶部,我需要添加一个带有作者照片的圆圈。

Here is my problem, I don't know where or how to do it. 这是我的问题,我不知道在哪里或怎么做。 I was thinking I should put a div position absolute to the featured image, and then make it circle. 我当时想我应该将div位置绝对放在特色图片上,然后使其变成圆圈。 But how can I do it if I do not have the featured image in code? 但是,如果代码中没有特色图片,该怎么办?

Here is my single.php, which it is not doing the job as I do not see my div for the picture: 这是我的single.php,它没有完成工作,因为我没有看到div的图片:

<?php get_header(); ?>

<div class="container">
    <?php
    if (have_posts()) {
        while (have_posts()) {
            the_post();

            if (in_category('solutions')) {
                the_content();
                ?>
              <div class="authorCircle">
                <img src="images/jules.jpg" alt=""/>
              </div>
          <?php
          } else {
              the_content();
          }
      } // end while
  } // end if
  ?>
</div>
  <?php
  get_footer();

So authorCircle is the div I want to see in the content of the post with category "solutions". 所以authorCircle是我要在帖子内容中看到的“解决方案”类别的div。

Any ideas how can I do it? 有什么想法我该怎么做? Should I put the div inside the_content()? 我应该将div放入the_content()吗?

Thank you in advance!! 先感谢您!!

Please use this code it will display author avatar at your code. 请使用此代码,它将在您的代码上显示作者头像。

<?php echo get_avatar( get_the_author_meta('ID'), 60); ?>

In above code respectivly you want get author id. 分别在上述代码中,您想要获得作者ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM