Access all of Typerocket. Get Pro.
Tabs
( v5 )
- # Getting Started
- # Single Tab
- # Set Description
- # Set Icon
- # Set Content
- # Set Active
- # Set URL
- # Tab For Repeaters
- # Layout Options
- # Sidebar
- # Footer
- # Title
- # Only Icons
Getting Started
If you use the theme options plugin, you will notice that there is a tabbed layout. You can create tabbed layouts with TypeRocket using the tr_tabs()
function.
$tabs = tr_tabs();
Once you have a tabs instance, you can start adding tabs using the tab()
method. The tab method takes three arguments.
- Tab Label - The tabs label as a
string
. - Icon Name - The name of an icon or
null
for no icon. - Content - This can be a
string
,callback
,Fieldset
, or anarray
ofField
objects.
$tabContentOne = "<p>Main content 1.</p>";
$tabContentTwo = "<p>Main content 2.</p>";
$tabs->tab('Tab 1', 'users', $tabContentOne);
$tabs->tab('Tab 2', 'books', $tabContentTwo);
echo $tabs;
Single Tab
You can work with individual tabs after adding them.
$tabs = tr_tabs();
$tab = $tabs->tab('Books', 'books');
Now you can use the $tab
variable to chain method.
Set Description
$tabContent = "List of books";
$tab->setDescription($tabContent);
Set Icon
$tab->setIcon('users');
Set Content
$tabContent = "<p>Main content 2.</p>";
$tab->apply($tabContent);
Set Active
$tab->setActive(true);
Set URL
Go to a URL instead of opening the tab on the same page.
$tab->setUrl('https://example.com/wp-admin/my-url');
Tab For Repeaters
$tabs = tr_tabs();
$tabs->tab('Date')->setFields($this->form->date('Date'));
$tabs->tab('Info')->setFields($this->form->text('Info'));
echo $form->repeater('Example')->setFields($tabs);
Layout Options
$tabs->layoutTopEnclosed();
$tabs->layoutLeftEnclosed();
$tabs->layoutTop();
$tabs->layoutLeft();
Sidebar
You can add a sidebar to main content tabs using the setSidebar()
method.
$sidebar = "<p>Sidebar content.</p>";
$tabs->setSidebar($sidebar);
Footer
You can add a footer to main content tabs using the setFooter()
method.
$footer = "<p>Footer content.</p>";
$tabs->setFooter($footer);
Title
You can add a title to main content tabs using the setTitle()
method.
$title = "Title content.";
$tabs->setTitle($title);
Only Icons
Only show the icons of tabs.
$tabs->onlyIcons();
Found a typo? Something is wrong in this documentation? Fork and edit it!