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
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, eg:
admin.php?page=my_plugin_page_slug&tab=second
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.