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>
My Answer:
To display the author of the post, you can use the `get_the_author()` function. However, this function only returns the author's display name. If you want to display the author's full name or other information, you can use the `get_the_author_meta()` function.
Here is an updated version of your code with the author included:
php
In this updated code, I have used the `get_the_post_thumbnail_url()` function to get the URL of the featured image and set it as the background image for the `.blog-image` element.
Make sure to add some CSS to style the background image properly.
Rate this post
3 of 5 based on 1459 votesComments