bous All American 11215 Posts user info edit post |
Okay... I'm using PHP right now and am using includes for the header/footer/etc that is constant on EVERY page. This way I can just update one html file and every page is updated.
However, I've run into a problem when it comes to this but wanting to do it for sub navigation. I want the page it's on w/in the subnav to be bold and have no link, but can't figure out the best way to do this.
What's the best way to go about doing this?
assign each page an id and figure it out that way somehow via css?
or make the navigation a separate php file where i can pass it a certain parameter on the pages and it can use it's own code to assign the bold/no link that way?
i guess i'm down to css or php, b/c i'm sure i can figure it out, but w/ php it may cost load times (although i'm sure nothing noticeable)
example (hardcoded):
<div id="subnav"> <ul id="subnav"> <li><strong>Item 1</strong></li> <li><a href="#">Item 2</a></li> <li><a href="#">Item 3</a></li> </ul> </div>
example (css): this way they will all have to be links and won't be able to remove them (which i don't like, but can live w/ it)
<body id="blah"> ... <div id="subnav"> <ul id="subnav"> <li id="item_1"><a href="#">Item 1</a></li> <li id="item_1"><a href="#">Item 2</a></li> <li id="item_1"><a href="#">Item 3</a></li> </ul> </div>
example (php): this would use code in the subnav.php file to make the item with "item_1" as its id to have no link and be bold
<div id="subnav"> <ul id="subnav"> <?php include("subnav.php&page=item_1"); ?> --- would that even work, or what's the format? </ul> </div>
I'd like to be able to make updates to the number of items and titles/links of the items in one place and not have to change the bold/whatever on EVERY SINGLE PAGE and it take FOREVER.
if this is confusing help me clarify it.
[Edited on July 6, 2006 at 10:09 PM. Reason : ] 7/6/2006 10:01:47 PM |
BigMan157 no u 103354 Posts user info edit post |
the way i'd do it would be to write up the whole subnav code in an include file, put all the subnav options in a database table, query it, have a while($ROW=mysql_fetch_object($result)) run, and be sorta like
if($ROW->link==$PHP_SELF) echo "<strong>$ROW->linkname</strong>"; else echo "<a href='$ROW->link'>$ROW->linkname</a>"; but then again, i'm not the most elegant of coders
if you are good with javascript i bet you could do it that way too, have it dynamically check the header, compare it to the links in the subnav, and alter the code
i don't think you could do it with just css alone though
[Edited on July 6, 2006 at 10:25 PM. Reason : javascript would prob be best to reduce server load but damned if i know how to do it]7/6/2006 10:22:40 PM |
bous All American 11215 Posts user info edit post |
i've got it working using php
avoiding mysql for this b/c it'd be faster w/o it since i don't have much data to work with 7/6/2006 11:31:30 PM |
BigMan157 no u 103354 Posts user info edit post |
yeah i just said mysql because it'd be quicker to modify/update/add items to the subnav 7/6/2006 11:49:26 PM |
mienutzich All American 4300 Posts user info edit post |
subnav.php
$output = ""; for($i=0;$i<numPage;$i++){ $output += "<li class=\"item"; if($i == $page){ $output += " itemselect"; } $output += "\"><a href="$whatever">$whatever2</a></li> } echo $output; ------------------------------ subnav.css
#subnav li.item { whateverstyle; } #subnav li.itemselect { font-weight: bold; }
----------------------------- outputs
<div id="subnav"> <ul id="subnav"> <li class="item itemselect">Item 1</li> <li class="item"><a href="#">Item 2</a></li> <li class="item"><a href="#">Item 3</a></li> </ul> </div>
------------------------------
This way you have one class you apply to all the links from the css file. And for the selected item you add the second class too it as well. This way you can modify the style from the css file without having to go back to the php code.
You can put the classes on the a's or the li's7/7/2006 7:25:30 PM |
bous All American 11215 Posts user info edit post |
i made a variable on the main page and then did the include on subnav.php which used that variable from the main page to know which item was to be selected.
i just did if statements so it's easier to add content and switch it around. 7/8/2006 2:28:53 PM |