tabselected, while unselected tabs have a class of tab.
Version: 1.0.2b
Author: David Burton
Author URI: http://dynamictangentconceptions.dtcnet.co.uk
*/
/* Copyright 2005 dtcnet (email : info@dynamictangentconceptions.dtcnet.co.uk)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$dtabs_current_version = '1.0.2b';
// dtc_add_pages() is the sink function for the 'admin_menu' hook
function dtab_add_pages() {
if (function_exists('add_options_page')) {
add_options_page('options-general.php', 'Tabs', 8, basename(__FILE__), 'dtab_option_page');
}
if (function_exists('add_management_page')) {
add_management_page('Manage Tabs', 'Tabs', 8, basename(__FILE__), 'dtab_manage_page');
}
}
function dtab_checked($option) {
if ($option == true) {
return ' checked';
}
}
// dtab_option_page outputs the tabs options preference pain
function dtab_option_page() {
add_option('dtabs_options', array('css' => ''));
$dtabs_options = get_option('dtabs_options');
if ($_GET['action'] == 'save') {
$dtabs_options = array( 'auto_css' => $_POST['auto_css'], 'css' => $_POST['css_code'], 'before' => $_POST['before'], 'after' => $_POST['after']);
update_option('dtabs_options',$dtabs_options);
?>
function hide(id){
eval("document.getElementById(\'"+id+"\').style.display=\'none\'");
}
function show(id){
eval("document.getElementById(\'"+id+"\').style.display=\'inline\'");
}
function more(contentid,titleid) {
if (eval("document.getElementById(\'"+contentid+"\').style.display==\'inline\'")) {
hide(contentid);
eval("document.getElementById(\'"+titleid+"\').style.backgroundPosition=\'top right\'");
}
else {
show(contentid);
eval("document.getElementById(\'"+titleid+"\').style.backgroundPosition=\'bottom right\'");
}
}
function extra(contentid,titleid) {
if (eval("document.getElementById(\'"+titleid+"\').checked == true")) {
eval("document.getElementById(\'"+contentid+"\').style.display=\'table-row\'");
}
else {
hide(contentid);
}
}
function set_css(use_default_css) {
default_css = "\n\
#tabbar ul li {\n\
display:inline;\n\
}\n\
#tabbar a {\n\
display: inline-table;\n\
text-align: center;\n\
vertical-align: middle;\n\
width: 100px;\n\
height: 25px;\n\
}\n\
.tab {\n\
background-color: white;\n\
display: inline;\n\
}\n\
.tabselected {\n\
background-color: grey;\n\
display: inline;\n\
}\n\
.dmenu {\n\
display: none;\n\
margin: 25px 0px 0px 2px;\n\
padding: 5px 5px 5px 5px;\n\
background-color: yellow;\n\
position: absolute;\n\
z-index: 100;\n\
filter:alpha(opacity=\'90\');\n\
opacity: .9;\n\
min-width: 88px;\n\
}\n\
";
';
if ($dtabs_options['css'] != NULL) {
echo 'if (use_default_css) {
document.getElementById(\'css_code\').value = default_css;
}
else {
document.getElementById(\'css_code\').value = \''.str_replace('
','\n\\', nl2br($dtabs_options['css'])).'\';
}
';
} else {
echo 'document.getElementById(\'css_code\').value = default_css;
';
}
echo '
}
Tab Options
Tick
Automatic css generation to have the dTabs plugin automatically produce css in the header of each page generated by your
Wordpress installation. You can use the default css as a guide for how to generate your own css which can be directedtly entered
into the css textarea. For more advanced css examples take a look at the
dTabs page on dtcnet.
Additionally, using the
html before and
html after textboxes, html can be added before and after each of your tabs.
This html will be placed outside of any specified in your theme. Tip: to generate horizontal tabs enter
<br /> in the
html after textbox (you will need to play around with
your theme to make it look pretty, but it serves as an example of how to use these options).
To add, remove, or edit your tabs click on Tabs on the Manage control pannel.
';
}
}
// dtab_manage_page outputs the tabs preference pain
function dtab_manage_page() {
global $wpdb;
$default = array(1 => array('name' => 'NULL', 'label' => 'Home', 'url' => '/', 'title' => 'Back to the main page', 'type' => 'blog'));
add_option('dtabs', $default);
$dtab = get_option('dtabs');
$total_tabs = count($dtab);
$title = 'Dynamic Tabs Management';
$complete_message = '';
$success_message = 'Save successful.';
$error_message = 'Error
';
$delete_message = 'Tab successfully deleted.';
$save_message = 'Settings successfully saved.';
$reset_message = 'dTab settings successfully reset to defaults.';
if ($_GET['action'] == 'edit') {
$title = $title.': Edit Tab';
$intro = '
Please specify the number, type, name, and url/path/permalink for the tab.
The number is the order in which the tab will appear in your tab bad, with 1 being the first.
Type refers to the destination of the tab.
If you select a page or category then you are presented with a list of the available tabs of your chosen type and the
url/path/permalink will automatically be filled in for you.
If you want the tab to link to external destiniation (ie not within Wordpress), the you can select the type other,
this allows you to fill in your own name and url/path/permalink.
In addition, you can specify a description for your tab which when your tabs are output in html, will be set as the tab\'s
title attribute.
';
} else {
$title = $title.': Overview';
$intro = '';
if ($_GET['action'] == 'save') {
$message = true;
$number = trim($_POST['number']);
$label = trim($_POST['label']);
$title = trim($_POST['title']);
$type = trim($_POST['type']);
$url = trim($_POST['url']);
$name = trim($_POST['name']);
$menu = $_POST['menu'];
$menuid = trim($_POST['id']);
if (!is_numeric($number) && empty($number)) {
$number = $total_tabs+1;
$success_message .= '
The tab number was set to '.$number.'.';
}
if (!is_numeric($number)) {
$number = ($total_tabs+1);
}
if ($number != $_GET['otab']) {
if ($number < 1) {
$success_message .= '
The tab number should be at least 1 and so was changed to 1.';
$number = 1;
} elseif ($number > ($total_tabs+1)) {
$success_message .= '
The tab number was changed to be only one higher than the previous total number of tabs';
$number = ($total_tabs+1);
}
if ($number < $_GET["otab"]) {
$temp = $dtab;
foreach ($temp as $i => $v) {
if (($i >= $number) && ($i < $_GET["otab"])) {
$dtab[$i+1] = $v;
}
}
} elseif ($number > $_GET["otab"]) {
$temp = $dtab;
foreach ($temp as $i => $v) {
if (($i <= $number) && ($i > $_GET["otab"])) {
$dtab[$i-1] = $v;
}
}
}
}
if (empty($label)) {
$success_message .= '
The tab name was also used for it\'s label.';
$label = strtoupper(substr($name,0,1)).strtolower(substr($name,1));
}
$dtab[$number] = array( 'name' => $name, 'label' => $label, 'url' => $url, 'title' => $title, 'type' => $type, 'menu' => $menu, 'id' => $menuid);
$success = true;
update_option('dtabs',$dtab);
} elseif ($_GET['action'] == 'delete') {
$message = true;
$complete_message .= $delete_message;
unset($dtab[$_GET['tab']]);
$temp = array_values($dtab);
$dtab = NULL;
foreach ($temp as $i => $v) {
$dtab[$i+1] = $v;
}
update_option('dtabs',$dtab);
} elseif ($_GET['action'] == 'reset') {
$message = true;
$complete_message .= $reset_message;
delete_option('dtabs',$default);
}
}
if ( $message == true ) {
if ( $error == true ) {
$complete_message .= $error_message;
}
if ( $success == true ) {
$complete_message .= $success_message;
}
$complete_message .= '
';
echo $complete_message;
} else {
echo '
';
} else {
echo '
| Number |
Name |
Label |
URL/Path/Permalink |
Description |
|
|
';
ksort($dtab);
if (is_array($dtab)) {
foreach ($dtab as $i => $v ) {
if ($i%2) {
echo '';
} else {
echo '
';
}
echo '
| '.$i.' |
';
if ($dtab[$i]["name"] == "NULL") {
echo 'blog/main page | ';
} else {
echo ''.$dtab[$i]["name"].' | ';
}
echo '
'.$dtab[$i]["label"].' |
';
if (strlen($dtab[$i]["url"]) >= 44) {
$short_url = substr($dtab[$i]["url"],0,20).'....'.substr($dtab[$i]["url"],strlen($dtab[$i]["url"])-20,20);
echo ''.$short_url.' | ';
} else {
echo ''.$dtab[$i]["url"].' | ';
}
echo '
'.$dtab[$i]["title"].' |
Edit |
Delete
|
';
}
}
echo '
';
?>
Dynamic tabs are hyperlinks with css formatting which changes depending on whether the page/category they link to is a parent of or the actual current page/post/category or not. For more information visit the dTabs page on dtcnet.
Please note that a dTab enabled theme is necessary to display your tabs.
A list of some dTab enabled themes is available here,
or find out how to dTab enable any theme here.
Both the name and the url/path/permalink of each tab are independantly stored in the dTab settings to save time when loading your blog. Therefore if you make any changes to the titles of pages or categories your tabs link to or the permalink structure of your Wordpress installation, you will need to reset the information for the tabs affected. This can be done by editing the affected tabs and simply pressing the update button.
To change how the tabs look click on Tabs on the Options control pannel, where you can add/remove/edit automatically generated css.
get_results("SELECT id, post_parent FROM $wpdb->posts", ARRAY_A);
$post = $wp_query->post;
foreach ($page_list as $page) {
$pages[$page['id']] = $page;
}
$id = $post->ID;
$parents = true;
while ($parents != false) {
$page_parents[$id] = $id;
$id = $pages[$id]['post_parent'];
if ($id == 0) {
$parents = false;
}
}
} elseif (is_single() OR is_category()) {
$cat_list = $wpdb->get_results("SELECT term_id, parent FROM $wpdb->term_taxonomy WHERE (taxonomy = 'category')", ARRAY_A);
foreach ($cat_list as $cat) {
$cats[$cat['term_id']] = $cat;
}
if (is_single()) {
$categories = get_the_category();
foreach ($categories as $cat) {
$id = $catid = $cat->cat_ID;
$parents = true;
while ($parents != false) {
$category_parents[$catid][$id] = $id;
$id = $cats[$id]['parent'];
if ($id == 0) {
$parents = false;
}
}
}
} else {
$id = $catid = intval(get_query_var('cat'));
$parents = true;
while ($parents != false) {
$category_parents[$catid][$id] = $id;
$id = $cats[$id]['parent'];
if ($id == 0) {
$parents = false;
}
}
}
}
$have_menus = NULL;
foreach ($dtabs as $i => $tab) {
if (is_page() AND $tab['type'] == 'page') {
$i = 0;
foreach ($page_parents as $page_id) {
if ($tab['id'] == $page_id) {
$current_tabs[] = array('name' => $tab['name'], 'level' => $i);
}
$i++;
}
} elseif ((is_single() AND ($tab['type'] == 'post' OR $tab['type'] == 'cat')) OR (is_category() AND $tab['type'] == 'cat')) {
if (is_single() AND $tab['type'] == 'post' AND $tab['id'] == $post->ID) {
$current_tabs[] = array('name' => $tab['name'], 'level' => 0);
}
foreach ($category_parents as $parents) {
$i = 0;
foreach ($parents as $cat_id) {
if ($tab['id'] == $cat_id) {
$current_tabs[] = array('name' => $tab['name'], 'level' => $i);
}
$i++;
}
}
}
if (isset($tab['menu']) AND $tab['menu']==true AND is_null($have_menus)) {
$have_menus = true;
}
}
if (is_archive() AND !is_category()) {
$current_tabs[] = array('name' => 'archives', 'level' => 0);
}
if (is_home() OR !isset($current_tabs)) {
$current_tab = 'NULL';
} else {
$current_tab = array('name' => $current_tabs[0]['name'], 'level' => $current_tabs[0]['level']);
foreach ($current_tabs as $ctab) {
if ($ctab['level'] < $current_tab['level']) {
$current_tab = $ctab;
}
}
$current_tab = $current_tab['name'];
}
$tabs = NULL;
foreach ($dtabs as $i => $tab) {
if ($have_menus == true) {
if (isset($tab['menu']) AND $tab['menu'] == true) {
$onmouseover = ' onmouseover="showmenu(\''.$tab['name'].'_menu\',\''.$tab['name'].'_button\');"';
$onmouseout = ' onmouseout="hidemenu();"';
echo '
';
} else {
$onmouseover = ' onmouseover="hidemenunow();"';
$onmouseout = '';
}
} else {
$onmouseover = '';
$onmouseout = '';
}
if ($tab['archives'] == 'post' OR $tab['type'] == 'bookmarks') {
$onclick = ' onclick="return false"';
} else {
$onclick = '';
}
if ($tab['type'] == 'blog') {
$url = get_bloginfo("url");
} elseif ($tab['type'] == 'cat') {
$url = get_category_link($tab['id']);
} elseif ($tab['type'] == 'post' OR $tab['type'] == 'page') {
$url = get_permalink($tab['id']);
} else {
$url = $tab['url'];
}
if ($current_tab == $tab['name']) {
$class = 'tabselected';
} else {
$class = 'tab';
}
if (!is_null($have_menus)) {
$id = ' id="'.$tab['name'].'_button"';
} else {
$id = NULL;
}
$tabs .= '
'.$dtabs_options['before'].$before.''.stripslashes($tab['label']).''.$after.$dtabs_options['after'].'';
}
echo '
';
}
}
/*CSS Styling*/
function dtabs_css() {
global $dtabs_options;
echo '
';
}
function dtabs_javascript() {
echo '
';
}
// Insert the dtc_add_pages() sink into the plugin hook list for 'admin_menu'
add_action('admin_menu', 'dtab_add_pages');
// Add auto css if necessary
if (is_array($dtabs_options = get_option('dtabs_options'))) {
if ($dtabs_options['auto_css']) {
add_filter('wp_head', 'dtabs_css', 2);
}
}
if (is_array($dtabs = get_option('dtabs'))) {
$outputjs = false;
foreach ($dtabs as $dtab) {
if ($dtab['menu'] == true) {
$outputjs = true;
}
}
if ($outputjs == true) {
add_filter('wp_head', 'dtabs_javascript', 2);
}
}
?>