What I'd like to do is if the current page is being viewed it disables the link.
My other issue is there will be articles in the site under the articles page. How would I have the articles with the title 092308.php cause the current page to be active.
you have an "if", now you need an "else"
There are a lot of ways to go about it. I would get the logic out of the menu though. something along the lines of...
As for the other part - I would do this by having the articles.php page be the active page, and have it include the content of the article instead.
so you would link to article.php?id=092308 or the like.
[Edit 1: OK, let's try this again. Apologies for making everyone scroll way to the right, but the only way I could prevent the numbers in square brackets from turning into links was by using the "code" tags. And no, unchecking the "Enable linkwords" checkbox before posting did absolutely nothing. Someone needs to look into that.]
[Edit2: If it makes it any easier, you can hit the edit button on this post and just copy and paste the text from there. How mind-blowingly annoying.]
For starters, what sort of error are you getting. To be honest, the code is making me dizzy... all that unnecessary opening and closing of php sections, etc.
Secondly, you have a typo: "churchess" for "churches" in the corresponding php section.
Thirdly, would you mind if I offered you a more streamlined solution? On my own website I have a very similar set-up. Actually, it's a lot more complex than what you're trying to do, so it should be even easier for you. Try this out. Put all the PHP code at the start of the document, before you even have your doctype declaration. This is not necessary, but I find that keep the logic separate, as DL put it, makes things neater (right now you have the code inside the menu). The array definition obviously should go on one line.
_____
code:
<?php
$menu_link = array("<a href=\"index.php\">Home</a>",
"<a href=\"about.php\">About</a>",
"<a href=\"sermons.php\">Sermons</a>",
"<a href=\"articles.php\">Articles</a>",
"<a href=\"gallery.php\">Gallery</a>",
"<a href=\"churches.php\">Churches</a>",
"<a href=\"cirectory.php\">Directory</a>",
"<a href=\"contact.php\">Contact</a>")
switch($currentPage)
{
case "index.php":
$menu_item[0] = "Home";
break;
case "about.php":
$menu_item[1] = "About";
break;
case "sermons.php":
$menu_item[2] = "Sermons";
break;
case "articles.php":
$menu_item[3] = "Articles";
break;
case "gallery.php":
$menu_item[4] = "Gallery";
break;
case "churches.php":
$menu_item[5] = "Churches";
break;
case "directory.php":
$menu_item[6] = "Directory";
break;
case "contact.php":
$menu_item[7] = "Contact";
break;
}
?>
(The following is within the HTML document, obviously)
<div id="menu">
<ul>
<li><?php echo($menu_item[0]); ?></li>
<li><?php echo($menu_item[1]); ?></li>
<li><?php echo($menu_item[2]); ?></li>
<li><?php echo($menu_item[3]); ?></li>
<li><?php echo($menu_item[4]); ?></li>
<li><?php echo($menu_item[5]); ?></li>
<li><?php echo($menu_item[6]); ?></li>
<li><?php echo($menu_item[7]); ?></li>
</ul>
</div>
_____
And that's it. Basically what it does is it sets up an array where everything is linked by default. Then it goes through a switch statement and changes the corresponding menu item with a non-linked item. Then you just display the menu and presto! This should work as is, but I typed it up on the spot, so it is possible a syntax error or two crept in. If you have any problems, let me know.
From: Lost Angeles Kalifornia, via Hawaii.... Insane since: Jun 2001
posted 09-24-2008 03:56
So let me make sure I get this right...
I put the first section in a file called menu.inc.php then I put that at the top of the page with.
Then I drop the second part where the menu would go.
I'm baffled trying to figure out the code. I have a handy dandy php book with simple examples, but they leave out the complex stuff like what I'm trying to do.
You would get an unexpected T_SWITCH error if the variable in the switch statement is not defined.
[Edit: In more detail... I think what this means is that the $currentPage variable is not being defined. How are you obtaining this variable?]
___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup
From: there...no..there..... Insane since: May 2001
posted 09-24-2008 22:06
also, the array needs to be $menu_item not $men_link. Good stuff Suho.
I used something similar and in using something like this it makes it easy to set the current state of the link in the CSS. Which is nice for users so they know where they are
From: Lost Angeles Kalifornia, via Hawaii.... Insane since: Jun 2001
posted 09-25-2008 08:55
Wow guys I really appreciate all the input. Just got in, it's about Midnight so I'll get to tweaking tomorrow morning. But big thanks for the contributions! May not seem like alot to you guys, but for me it's HUUUGE!
Just make sure that, if you use my code (or a variation thereof), you take into account the subsequent corrections to all the stupid little mistakes I made.
From: Lost Angeles Kalifornia, via Hawaii.... Insane since: Jun 2001
posted 09-25-2008 20:11
It works now, but how would I disable the link if you're on the current page? I was told that best practice would be to have the link not be active. If it's a pain, I'm not going to worry about it, but if it's relatively simple then I'll go for it.
From: there...no..there..... Insane since: May 2001
posted 09-25-2008 23:07
I'm not sure why that would be the "best practice". If anything, I like to set the current state of the menu according to what page they are on.
You can do that easily with the script Suho provided.
Just add something like $bodyClass = "home"; for the index page and so on. Then echo that in the html part. In the css, set the current state like the link above. I can give more details once I get back home if you'd like.
From: Lost Angeles Kalifornia, via Hawaii.... Insane since: Jun 2001
posted 09-26-2008 03:15
The current state works, I'm fine with it being active, but I thought it optimum to deactivate current page link so it doesnt link to itself. thats all. :-)