티스토리 뷰
1. 테마 > functions.php 코드추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | //사용자와 관리자의 메뉴를 다르게 보이고 싶을 때 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 코드 추가 => 직원전용페이지로 이동 및 로그인/로그아웃 설정
1 2 3 4 5 6 7 | <?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 파일 생성 -> 로그인폼 작성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <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 코드수정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?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(); } ?> |
'개발기록 > PHP' 카테고리의 다른 글
GNB 하단 이미지 페이지별로 다르게 넣고 싶을 때 (0) | 2017.04.13 |
---|---|
PC+MOBILE 일 경우 상단바 수정 (0) | 2017.04.13 |
버튼 클릭시 이메일로 내용 전송하기 (0) | 2017.04.05 |
라디오 버튼 선택 값 다른 페이지에서 불러오기 (0) | 2017.04.05 |
자유게시판 댓글 및 답댓글 (0) | 2017.04.04 |