How to create a tab menu on a Wordpress admin page

this is my update code

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
}

I want 'user_funct ()' to create a tab with a wordpress style like this


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


how to create other content using the link tab menu

thank

+4
source share
1 answer

Here's how you can do it:

First you need to create a function that creates a structure depending on the selected tab selected:

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;
}

Then, in the callback function called to display the page that will contain the tabs, you should use this function as follows:

<?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
+7

Source: https://habr.com/ru/post/1545786/


All Articles