简体   繁体   中英

How to get the current Post author URL and his display name

I want to show all posts from the current author of the post. Here is the code I have implemented:

echo '<h2 class="entry-title"><a href="'.get_author_posts_url( get_the_author_meta( 'ID' )'">'.the_author().'</a></h2>';

BTW, I'm confused regarding the single bracket. When I start with { echo ' } then how it is possible to display this call:

get_author_posts_url( get_the_author_meta( 'ID' )

as the ID parameter has both single brackets. I'm getting tons of errors and don't know how to place the author profile link in order to display all his post under his Display Name. Thanks in advance. Have a nice weekend!

You should call the function before and save their output to a variable, so u can just echo out variable. But i believe your functions do not work at all, (function inside function, passing string ID as parameter? Is that working ok?)

Im not sure how your code looks but for example:

$url = get_author_posts_url(get_the_author_meta('ID');
$author = the_author();

echo '<h2 class="entry-title"><a href="'. $url . '">'. $author .'</a></h2>';

You also missed one . (dot) after

get_the_author_meta( 'ID' )

Can you post your functions code?

As for the single quotes, google up Escaping quotation marks

You can generate this link, within The Loop , by using thethe_author_posts_link Template Tag. For example: source page

<p>Written by: 
<?php the_author_posts_link(); ?></p>

output will look like this:

<a href="http://localhost:8888/siteurl/author/admin/" title="Posts by admin" rel="author">admin</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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