• Resolved desaraev6

    (@desaraev6)


    I’m writing a plugin for WordPress that uses a menu and submenu. Inside one of the Submenu pages I want to include tabs so that the menu isn’t so clustered with submenus. This isn’t that big of a deal but would definitely make it look nicer. I’ve seen a lot of html javascript and jquery options but they are typically clunky. Finally I came across a nice PHP option from onedesigns

    http://www.onedesigns.com/tutorials/separate-multiple-theme-options-pages-using-tabs/comment-page-1#nogo

    I edited this code so that it wasn’t going to be used for a themes menu but for my plugin menu.

    // mt_sublevel_page3() displays the page content for the third submenu
    // of the custom Pedigree Builder Admin menu
    // the code below creates the tabs
    function mt_sublevel_page3($current = 'about') {
    	$tabs = array( 'about' => 'About Us', 'social' => 'Social Media', 'web' => 'Web Design', 'page9' => 'Videos' );
        $links = array();
        foreach( $tabs as $tab => $name ) :
            if ( $tab == $current ) :
                $links[] = "<a class='nav-tab nav-tab-active' href='?page=sub-$tab&tab=$tab'>$name</a>";
            else :
                $links[] = "<a class='nav-tab' href='?page=sub-$tab&tab=$tab'>$name</a>";
            endif;
        endforeach;
        echo '<h2>';
        foreach ( $links as $link )
            echo $link;
        echo '</h2><hr>';
    	// use the "PEDIGREE ADMIN CSS" style
        echo '<link rel="stylesheet" href="/wp-content/plugins/PEDIGREE/admin/css/pedigree_admin.css" type="text/css" />';
    
      if ( $pagenow == 'pedigree_about.php' && $_GET['page'] == 'mt_sublevel_page3' ) :
        if ( isset ( $_GET['tab'] ) ) :
            $tab = $_GET['tab'];
        else:
            $tab = 'about';
        endif;
        switch ( $tab ) :
            case 'about' :
                mt_sublevel_page3();
                break;
            case 'social' :
                mt_sublevel_page3();
                break;
            case 'web' :
                mt_sublevel_page3();
                break;
            case 'video' :
                mt_sublevel_page9();
                break;
        endswitch;
    endif;

    The only problem is that the content for these pages don’t show up right. I’ve edited the case values, the page now and even tried adding includes, but often just broke the page.

    Thoughts? Help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The problem lies here:

    href='?page=sub-$tab&tab=$tab'

    This would translate into something like this:

    href='?page=sub-about&tab=about'

    the page parameter should be the page slug declared in the add_submenu_page function or what function you have used to add the menu entry, which in this case is mt_sublevel_page3. Most probably the slug sub-about does not exist, that’s why it’s probably returning blank or 404 results.

    This would be the correct implementation:

    href='?page=mt_sublevel_page3&tab=$tab'

    Thread Starter desaraev6

    (@desaraev6)

    Thanks I ended up getting it. Finished the problem a little differently only now the plugin works perfect but seems to make a few of my admin features not work perfect. For example the dropdowns and some of the bulk options. I could send the code but its 4 pages. So if anyone is interested in checking it out and helping let me know and I’ll send you a copy.

    — Desaraev

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Writing a Plugin with a Sub Menu and Tabs within the Plugin Page’ is closed to new replies.