sourcecode

관리 페이지에서 탭 메뉴를 만드는 방법 워드 프레스

codebag 2023. 10. 20. 13:39
반응형

관리 페이지에서 탭 메뉴를 만드는 방법 워드 프레스

이것은 나의 업데이트 코드입니다.

if (is_admin())
{
    add_action('admin_menu', 'user_menu');
}

function user_menu()
{
    add_menu_page('Pesananku', 'Pesananku', 'subscriber', 'userslug',
    'user_funct',get_template_directory_uri().'/img/favicon.ico',22);
}
function user_funct()
{
   ?>
<h2 class="nav-tab-wrapper">
    <a href="#tab1" class="nav-tab">Tab #1</a>
    <a href="#tab2" class="nav-tab nav-tab-active">Tab #2</a>
    <a href="#tab3" class="nav-tab">Tab #3</a>
    </h2>
  <div id="tab1"><!--content tab1--></div>
  <div id="tab2"><!--content tab2--></div>
  <div id="tab3"><!--content tab3--></div>
   <?php
}

나는 'user_funct ()' create 탭을 만들고 싶습니다. 이렇게 스타일링 워드를 누르세요.


http://postimg.org/image/h3nttjhof/


링크 탭 메뉴로 다른 컨텐츠를 만드는 방법

감사해요.

이것이 당신이 그것을 할 수 있는 방법입니다.

먼저 선택한 현재 탭에 따라 구조를 만드는 함수를 만들어야 합니다.

function page_tabs( $current = 'first' ) {
    $tabs = array(
        'first'   => __( 'First tab', 'plugin-textdomain' ), 
        'second'  => __( 'Second tab', 'plugin-textdomain' )
    );
    $html = '<h2 class="nav-tab-wrapper">';
    foreach( $tabs as $tab => $name ){
        $class = ( $tab == $current ) ? 'nav-tab-active' : '';
        $html .= '<a class="nav-tab ' . $class . '" href="?page=ipl_dbx_import_export&tab=' . $tab . '">' . $name . '</a>';
    }
    $html .= '</h2>';
    echo $html;
}

그런 다음 탭이 포함된 페이지를 표시하기 위해 호출되는 콜백 기능에서는 다음과 같이 이 기능을 사용해야 합니다.

<?php
// Code displayed before the tabs (outside)
// Tabs
$tab = ( ! empty( $_GET['tab'] ) ) ? esc_attr( $_GET['tab'] ) : 'first';
page_tabs( $tab );

if ( $tab == 'first' ) {
    // add the code you want to be displayed in the first tab
}
else {
    // add the code you want to be displayed in the second tab
}
// Code after the tabs (outside)
?>

또한 페이지를 호출하면 GET 값을 추가할 수 있습니다.tab표시할 탭에 해당합니다. 예:

admin.php?page=my_plugin_page_slug&tab=second

언급URL : https://stackoverflow.com/questions/24378753/how-to-create-tab-menu-in-admin-page-wordpress

반응형