skip to Main Content

I’m editing single post (single.php) in WordPress in order to rearrange where I want to show blog title, author, date and featured image.

So far I’ve managed to pull date and title and featured image, but not author.

Can somebody help me out, what is the correct function to call author? I was also wondering if it’s possible to put featured image as background image on the .blog-info element, I don’t know if I can pull just the source image?

This is where I’m at so far:

<div class="blog-info">
  <div class="blog-date"><?php echo get_the_date() ?></div>
  <div class="blog-title"><?php echo get_the_title() ?></div>
  <div class="blog-author">written by <span class="blog-author-name"><?php echo get_the_author() ?></span></div>
  <div class="blog-image">
    <img src="<?php the_post_thumbnail(); ?>">
  </div>
</div>

2

Answers


  1. Chosen as BEST ANSWER

    I've managed to solve it by adding:

    <?php $post = get_post(); ?>
    <?php setup_postdata($post); ?>
    <?php echo get_the_author(); ?
    

    Thanks to Brad Holmes for all the help!


  2. i will answer your image question as you say you can just pull the image into the div like so

    <div class="blog-info" style="background-image: url('<?php the_post_thumbnail(); ?>')"></div>
    

    as we have already fixed your author question in chat but please try not to ask two questions at a time as per rules of StackOverflow

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search