티스토리 뷰

1. 테마 > functions.php 코드추가
//사용자와 관리자의 메뉴를 다르게 보이고 싶을 때
function add_usermenu_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items="";//gnb메뉴 초기화
$current_user = wp_get_current_user();
$items .= '<li>'.$current_user->display_name.'님을 환영합니다.</li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
$items = $items;
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_usermenu_link', 10, 2 );

//사용자 페이지 로그아웃시 이동될 페이지 설정
function wpse_44020_logout_redirect($logouturl){
return $logouturl . '&redirect_to='.esc_url( home_url( '/' ) );
}
add_filter('logout_url', 'wpse_44020_logout_redirect');
2. header.php 코드 추가 => 직원전용페이지로 이동 및 로그인/로그아웃 설정
<?php if (is_user_logged_in() ) {
echo '<li><a href="'. wp_logout_url() .'">로그아웃</a></li>';
}
elseif (!is_user_logged_in()) {
echo '<li><a href="'. site_url('?page_id=95') .'">직원전용</a></li>';
}
?>
3. content-user-login.php 파일 생성 -> 로그인폼 작성
<form name="loginform" id="loginform" action="<?php esc_url( home_url( '/' ) );?>wp-login.php" method="post">
<p><label for="user_login">사용자명<br />
<input type="text" name="log" id="user_login" class="input" size="20" /></label>
</p>
<p>
<label for="user_pass">비밀번호<br />
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
</p>
<p class="submit">
<input type="button" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="로그인"/>
<input type="hidden" name="redirect_to" value="<?php echo home_url( '/' )?>?page_id=106" />
<input type="hidden" name="testcookie" value="1" />
</p>
</form>
<script src="<?php bloginfo("template_url")?>/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
<!--
jQuery(function($){
$("#wp-submit").click(function() {

document.loginform.submit();

return false;
})

})
//-->
</script>
4. page.php 코드수정
<?php
/**
* The template for displaying all pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site may use a
* different template.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
* @version 1.0
*/
if($post->post_title =="직원로그인"){}
else{ get_header(); }
?>

<?php while ( have_posts() ) : the_post(); ?>

<?php //get_template_part( 'content', 'page' );
if($post->post_title =="직원로그인"){
get_template_part( 'content', 'user-login' );
}else{
get_template_part( 'content', 'page' );
}
?>
<?php endwhile; // end of the loop. ?>
<?php
if($post->post_title =="직원로그인"){}
else{ get_footer(); }
?>
댓글
최근에 달린 댓글
Total
Today
Yesterday