【问题标题】:How can I display author id on the author page如何在作者页面上显示作者 ID
【发布时间】:2023-01-19 05:48:50
【问题描述】:

我正在尝试使用我创建的简码在作者页面上显示作者 ID,但它目前无法正常工作,因为简码仅输出管理员 ID。 这是我在短代码中返回的内容:

return get_the_author_meta('ID'); 

【问题讨论】:

  • 你能发布整个简码吗?

标签: wordpress


【解决方案1】:

工作代码:

function author_id_shortcode(){
    ob_start();
    
    // We get the author ID outside loop.
    global $post;
    $author_id = $post->post_author;
    
    //  Now get the author ID inside loop.
    $author_id = get_the_author_meta( 'ID' );
    
    $output = get_the_author_meta( 'ID', $author_id );

    ob_end_clean();
    return $output;
    
}
add_shortcode( 'author_id', 'author_id_shortcode' );

使用 [author_id] 调用简码

【讨论】:

  • 谢谢,这看起来和我的几乎一模一样。购买 我更改了所有内容以匹配您的代码,但它仍然返回管理员的 ID 而不是作者的 ID。
  • 有点奇怪。向我们展示您的代码。
【解决方案2】:

请在 author.php 上尝试以下代码

if (is_author()){
    $author = get_queried_object();
    $author_id = $author->ID;
    echo $author_id;
}

【讨论】:

    猜你喜欢
    • 2012-06-03
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多