Page 1 of 1
Creating a "tab" menu with php?
Posted: Fri Sep 24, 2004 3:19 pm
by Downleader
Hi, I've got the following situation on my site.
-----------> ------------------------------------------
menu.php | |
| headerpicture |
-------------------------------------------
| Home | Forum | Downloads | Links|
------------> ----------------------------------------------
> content --------------------->
I'll hope you understand it. On each page I want to include (php include) the menu.php so it is not difficult to change it when I want to. The menu is made of tables. What I want are links like this:
http://www.mydomain.com/?page=forum or /index.php?page=forum
I would like to know if it is possible If I click on the "forum" link, a php-script is loading the "forum"-content and the php script is changing the background colour of the table-cell with the forum link.
If this works, you've got a menu like a tab menu, without having to change the menu on all the pages. I'll hope somebody is understanding. Does somebody know a script for it?
Thanks in advance and sorry for my bad english.

Posted: Fri Sep 24, 2004 3:26 pm
by John Cartwright
you could create a function like
Code: Select all
function tabcheck($name)
{
if ($_GET['page'] == $name ? $bg = '#FFFFFF' : $bg = '#000000');
return $bg;
}
Hope this gives you an idea...
Posted: Fri Sep 24, 2004 4:31 pm
by m3mn0n
Or if you switch to frames, JavaScript could give you some help.
Research: [google]javascript onClick table background change[/google]
Posted: Sat Sep 25, 2004 2:37 am
by Downleader
Okay, before everyone thinks that I know a lot of php, I don't.
I've founden something in an onther script like this:
<td class="<?php echo ($page == 'categories') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_categories.php">Categories</a></b></td>
The "puncon1cent" and "puncent" are defined in a stylesheet. When I click on a link, the menu automatic change to the correct stylesheet (and then the background changes).
Can somebody tell me how this works, cause it seems to be very simple, but I don't know how this script see on which page I am.
In this script the header.php is inserted with "require" what is the difference between it and "include"
And I don't care if links are like this: ../admin.php or page?admin. I'd prefer the first. I just want the most simple option
The whole script:
Code: Select all
<?php
//
// Displays link to admin pages (for admins)
//
function admin_menu($page = '')
{
?>
<table class="punspacer" cellspacing="1" cellpadding="4">
<tr>
<td class="<?php echo ($page == 'categories') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_categories.php">Categories</a></b></td>
<td class="<?php echo ($page == 'forums') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_forums.php">Forums</a></b></td>
<td class="<?php echo ($page == 'users') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_users.php">Users</a></b></td>
<td class="<?php echo ($page == 'options') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_options.php">Options</a></b></td>
<td class="<?php echo ($page == 'permissions') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_permissions.php">Permissions</a></b></td>
<td class="<?php echo ($page == 'censoring') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_censoring.php">Censoring</a></b></td>
<td class="<?php echo ($page == 'ranks') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_ranks.php">Ranks</a></b></td>
<td class="<?php echo ($page == 'bans') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_bans.php">Bans</a></b></td>
<td class="<?php echo ($page == 'prune') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_prune.php">Prune</a></b></td>
<td class="<?php echo ($page == 'maintenance') ? 'puncon1cent' : 'puncent'; ?>" style="width: 10%; white-space: nowrap"><b><a href="admin_maintenance.php">Maintenance</a></b></td>
<td class="<?php echo ($page == 'reports') ? 'puncon1cent' : 'puncent'; ?>" style="width: 9%; white-space: nowrap"><b><a href="admin_reports.php">Reports</a></b></td>
</tr>
</table>
<?php
}
Thanks
?>
Posted: Sat Sep 25, 2004 9:02 am
by John Cartwright
i meant more or so something alongs the lines of this
Code: Select all
<style type="text/css">
.puncon1cent {
width: 9%;
white-space: nowrap;
background-color: #FFFFFF;
}
.puncent {
width: 9%;
white-space: nowrap;
background-color: #000000;
}
</style>
<?
function admin_menu($name)
{
if ($_GET['page'] == $name ? $class= 'puncon1cent' : class = 'puncent';
return $class;
}
?>
<table class="punspacer" cellspacing="1" cellpadding="4">
<tr>
<td class="<?= admin_menu('categories'); ?>"><b><a href="admin_categories.php">Categories</a></b></td>
<td class="<?= admin_menu('forums'); ?>"><b><a href="admin_forums.php">Forums</a></b></td>
<td class="<?= admin_menu('users'); ?>"><b><a href="admin_users.php">Users</a></b></td>
<td class="<?= admin_menu('options'); ?>"><b><a href="admin_options.php">Options</a></b></td>
<td class="<?= admin_menu('permissions'); ?>"><b><a href="admin_permissions.php">Permissions</a></b></td>
<td class="<?= admin_menu('censoring'); ?>"><b><a href="admin_censoring.php">Censoring</a></b></td>
<td class="<?= admin_menu('ranks'); ?>"><b><a href="admin_ranks.php">Ranks</a></b></td>
<td class="<?= admin_menu('bans'); ?>"><b><a href="admin_bans.php">Bans</a></b></td>
<td class="<?= admin_menu('prune'); ?>"><b><a href="admin_prune.php">Prune</a></b></td>
<td class="<?= admin_menu('maintenance'); ?>"><b><a href="admin_maintenance.php">Maintenance</a></b></td>
<td class="<?= admin_menu('reports'); ?>"><b><a href="admin_reports.php">Reports</a></b></td>
</tr>
</table>
Posted: Sat Sep 25, 2004 10:54 am
by Downleader
But in this script, how do I define the page name in the content page. And how are the links working: page?=test or /test.php
Thanks
Posted: Sat Sep 25, 2004 10:55 am
by feyd
it's specified through $_GET['page'] directly.
Posted: Sat Sep 25, 2004 11:09 am
by Downleader
I tried it but php says:
Code: Select all
Parse error: parse error, unexpected T_CLASS in /var/www/html/users/89ggg/test3/menu.php on line 5
This is line 5
Code: Select all
<?php
if ($_GET['page'] == $name ? $class= 'puncon1cent' : class = 'puncent';
?>
Posted: Sat Sep 25, 2004 11:15 am
by timvw
http://www.alistapart.com/articles/keepingcurrent/
Although i wouldn't test it like they do.
Code: Select all
$pages = array('page1.php' => 'Nice Name', 'page2.php' => 'Nicer name');
foreach($pages as $page => $label)
{
echo "<li id='";
if ($_GET['page'] == $page)
{
echo "notcurrent";
}
else
{
echo "currentpage";
}
echo "'><a href='$page'>$label</a></li>";
}
Posted: Sat Sep 25, 2004 11:47 am
by vigge89
here's how my menu works, maybe you'll find something of it useful
Code: Select all
$menu_count = 0;
$query['menu'] = mysql_query ("SELECT `id`,`pos`,`title`,`curl` FROM `content` WHERE `visible` = 1 ORDER BY `pos`");
##### loop trough each page, adding it to the menu
while ($cmenu = mysql_fetch_assoc ($query['menu'])) {
if (!empty ($cmenu['curl'])) { $smenu['link'] = $cmenu['curl']; } // if link is set to link to a external file
else { $smenu['link'] = "/p/{$cmenu['id']}/"; } // normal internal page link
$output['menu'] .= "<li";
$output['menu'] .= "><a href='{$smenu['link']}' title='{$cmenu['title']}'";
if ($output['id'] == $cmenu['id'] || $output['pid'] == $cmenu['id']) $output['menu'] .= " id='active'";
$output['menu'] .= ">{$cmenu['title']}</a></li>";
$menu_count++;
} ## /loop trough each page, adding it to the menu
Posted: Sat Sep 25, 2004 5:40 pm
by Downleader