繁体   English   中英

WordPress如何创建自定义(恢复)页面URL Slug +作者ID Slug

[英]WordPress How to create custom (Resume) page url slug + author id slug

我已经为我们的用户创建了自定义页面(Resume / CV)模板,以显示他们的信息,例如“头像,名称,说明等。

我通过使用$current_user = wp_get_current_user();获得了用户信息$current_user = wp_get_current_user();

每个用户访问此页面时,只能看到他的信息! 但是,如果我需要将此页面与author.php公开,那么所有用户都可以看到彼此的简历。

所以现在页面URL是https://www.website.com/resume/

我需要此页面为https://www.website.com/resume/?author=id

有任何选项来获取用户数据,而不是$current_user = wp_get_current_user(); 将此页面公开给所有人!

更新1

简历页面模板

<?php 
/**
 * Template Name: Resume Page
 */

$user = FALSE;
if (!empty($_GET['author'])) {
   $user = get_user_by('ID',$_GET['author']);
} else  {
   $user = wp_get_current_user();
}

get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

          <div class="pic"><?php echo get_avatar( $user->ID, 200 ); ?></div>
          <span class="first-name"><?php echo $user->display_name; ?></span>
          <span class="subtitle"><?php echo $user->profession; ?></span>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php
get_sidebar();
get_footer();

我现在正在尝试在author.php添加href链接,但它始终返回未找到的页面! 那么,如何创建属于作者ID的链接,以便任何人都可以轻松看到用户简历?

<?php 
if ( is_user_logged_in() ):
    echo '<div class="user-resume">';
    echo "<a href=\"".get_bloginfo('url')."/resume/?author=";
    echo $curauth->ID;
    echo "\">";
    echo "See full resume";
    echo "</a>";
    echo "</div>";
endif;
?>

我想做的是https://www.website.com/resume/?author=id

更新2

author.php文件

<?php get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

    <?php
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    ?>

    <?php echo $curauth->first_name .' '. $curauth->last_name; ?>
    <?php echo get_avatar( $curauth->ID, 200 ); ?>
    // and so on...

        </main><!-- #main -->
    </div><!-- #primary -->

<?php
get_sidebar();
get_footer();

您可以检查是否传递了author参数,并根据在该参数中传递的ID查询用户。 如果未传递任何参数,它将查询已登录的当前用户。

$user = FALSE;
if (!empty($_GET['author']) {
   $user = get_user_by('ID',$_GET['author']);
} else  {
   $user = wp_get_current_user();
}

不过,您应该添加更多验证,以检查ID是否查询有效用户或访问者当前是否已以用户身份登录。

更新更新

关于当前用户的简历的链接,您可以执行以下操作:

echo site_url('/resume/?author=' . get_current_user_id());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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