Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create tab menu in admin page wordpress

Tags:

php

wordpress

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()' create tab with styling wordpress like this


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


how to create different content with link tab menu

Thanks

like image 694
Iwan Firmawan Avatar asked Jun 24 '14 05:06

Iwan Firmawan


People also ask

How do you set tabs in WordPress page?

To get a quick grasp of the tabs we'll be creating, go to Appearance/Themes in the WordPress admin area. You will find two tabs there: “Manage Themes” and “Install Themes.” When you click on one, the content changes and the tab's title is highlighted.


1 Answers

Here is how you can go about it;

First, you need to create a function that create the structure depending on the current 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 which will contain the tabs, you need to use this function like that:

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

Also then you call the page, you can add a GET value called tab corresponding to the tab you want to display, e.g.:

admin.php?page=my_plugin_page_slug&tab=second
like image 197
Dexter0015 Avatar answered Oct 26 '22 23:10

Dexter0015