【问题标题】:Get Wordpress User Profile Url/Link by ID按 ID 获取 Wordpress 用户配置文件 URL/链接
【发布时间】:2014-01-10 12:52:23
【问题描述】:

我设法显示了来自主站点 xxxxx.com/ 的用户个人资料图片 在我的 bbpress 论坛 xxxxx.com/forum/ 中使用以下代码:

<?php $user_info = get_user_by('id', $wp_query->query_vars['author']); echo get_avatar($user_info->ID, '150'); ?>

问题:

我怎样才能用同样的方法获得像 xxxxxx.com/user/username 这样的用户资料 URL/LINK?

非常感谢!

【问题讨论】:

    标签: php jquery wordpress


    【解决方案1】:

    为了获得具有好名字的用户链接,请使用 2 个函数:

    【讨论】:

      【解决方案2】:

      如果你想从管理员端编辑用户,那么你可以使用这个:

      function get_admin_edit_user_link( $user_id ){
      
          if ( get_current_user_id() == $user_id )
             $edit_link = get_edit_profile_url( $user_id );
          else
             $edit_link = add_query_arg( 'user_id', $user_id, self_admin_url( 'user-edit.php'));
      
          return $edit_link;
      }
      

      【讨论】:

        【解决方案3】:

        用户页面 URL 有效

        wp 函数 => get_author_posts_url(int $author_id, string $author_nicename = '')

        <?php echo get_author_posts_url($user_id); ?>
        
        output: https://example.com/author/username/
        

        参考链接:https://codex.wordpress.org/Function_Reference/get_the_author_link

        【讨论】:

          【解决方案4】:

          要获取用户的个人资料链接,如 xxxxxx.com/author/username/,请使用以下函数:

          <?php get_author_posts_url( $author_id, $author_nicename ); ?>
          

          这里是documentation

          【讨论】:

            【解决方案5】:

            这个功能应该有助于: https://codex.wordpress.org/Template_Tags/the_author_meta the_author_meta( $field, $userID );

            对于个人资料链接,您需要该字段的“user_url”

            【讨论】:

            • 澄清一下,user_url 是用户在编辑个人资料时输入的网站 (www.mywebsite.com)。要获取用户作者页面,例如/author/john-doe,请使用get_author_posts_url($author_id) 方法。
            猜你喜欢
            • 1970-01-01
            • 2019-04-07
            • 2015-07-09
            • 1970-01-01
            • 1970-01-01
            • 2016-12-07
            • 1970-01-01
            • 2013-05-15
            • 2011-04-09
            相关资源
            最近更新 更多