Trouble making the navigation indicate the current page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
coryartfitz
Forum Newbie
Posts: 1
Joined: Thu Jun 14, 2012 9:43 am

Trouble making the navigation indicate the current page

Post by coryartfitz »

Hello,

I am new to php and coud use some help. I would like to make the curent navigation link bold to show the user where they are. The problem is that I cannot use the techniques like giving the body a unique id because I only have one body tag. I also tried giving the index.php and contact.php a <? $page='contact' ?> type of code and then apply that to the nav links, but it still didn't work (I probably did it wrong though.) I am using <?php require_once 'header.php' ?> to call the header which includes the <body> and NAV, into the index.php. Any help would be greatly appreciated.

Here is a breakdown of my code:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

header.php (The nav is currently here because it is actually located in the header div)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>BRIAND artistry</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<div id="wrapper">
<div id="header">
<a href="index.php">
<h1 id="logo">BRIAN<span class="red">D</span></h1>
<h2 id="logo2">Artistry</h2>
<h2 id="tag">The art of <span id="smallcaps">Brian DeClercq</span></h2>
</a>
<div id="nav">
<ul>
<li><a href ="index.php">Portfolio</a></li>
<li>|</li>
<li><a href ="contact.php">Contact</a></li>
</ul>
</div>
</div>
<div id="spacer"> <!--this is just a color div between the header and content -->

</div>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

index.php (home page)

<?php require_once 'header.php' ?>

<div id="content">
<div id="bio">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div id="portfolio">
<h3 class="heading">Bone Knight</h3>
<img src="images/bone_knight.jpg" alt="Bone Knight" class="img"/>
<h3 class="heading">Demon</h3>
<img src="images/demon.jpg" alt="Bone Knight" class="img"/>
<h3 class="heading">King</h3>
<img src="images/king.jpg" alt="Bone Knight" class="img"/>
<h3 class="heading">Pig Bat</h3>
<img src="images/pig_bat.jpg" alt="Bone Knight" class="img"/>
<h3 class="heading">Wizard</h3>
<img src="images/wizard.jpg" alt="Bone Knight" class="img"/>
</div>
</div>

<?php require_once 'footer.php' ?>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

footer.php

<div id="footer">
<ul>
<li>Copyright &copy; 2012</li>
<li><a href="index.php">BRIAN<span class="red">D</span> <span id="italic">Artistry</span></a></li>
</ul>
</div>
</div> <!--close wrapper -->
</body>
</html>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

contact.php (other nav item)

<?php require_once 'header.php' ?>

<div id="content">
<div id="bio">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>

<?php require_once 'footer.php' ?>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Trouble making the navigation indicate the current page

Post by Celauran »

What about using $_SERVER['PHP_SELF']?
Post Reply