繁体   English   中英

如何在管理页面wordpress中创建选项卡菜单

[英]how to create tab menu in admin page wordpress

这是我的更新代码

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() '创建选项卡与样式wordpress像这样


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

然后你调用页面,你可以添加一个名为tab的GET值,对应于你想要显示的选项卡,例如:

admin.php?page=my_plugin_page_slug&tab=second

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM