Click here to Skip to main content
14,603,943 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello everyone
I have created a simple website in PHP. I am using include functions for topnav,header,menu,sidebar and footer.
Now, i am having couple of issues in that:
1. Whenver I click on any menu item the title of my page is all the same on all pages.
2. I wanted to change the background color of the selected menu item (I am able to do it using CSS but if not using include funtions).
The code is like:
TOP nav.php
<br />
<pre lang="xml"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><br />
<html><br />
<head><br />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"><br />
<title>My title goes here!</title><br />
<br />
<link rel="stylesheet" type="text/css" href="style/style.css"><br />
<br />
</head><br />
<body><br />
<div id="wrapper"><br />
    <div id="topbar"><br />
        <div class="date"><?php echo  date("l jS \of F Y ");?></div><br />
        <ul class="topnav"><br />
<br />
                <li><a href="#">About us</a></li><br />
                <li><a href="contact.php">Contact us</a></li><br />
            </ul><br />
<br />
    </div></pre><br />

Since all my html part like title description etc are saved in topnav.php, i am not able to change the title on index.php and so on.
Please guide like on which file i need to write the code like
<br />
<pre lang="php"><?php<br />
$title="";<br />
switch ($title){<br />
case "index.php":<br />
 $title= "index title here";<br />
<br />
 break;<br />
<br />
case  "about.php":<br />
 $title= "about title here";<br />
<br />
 break;<br />
}<br />
<br />
?></pre><br />
<br />
Posted
Updated 8-Oct-19 20:29pm
Rate this:
Please Sign up or sign in to vote.

Solution 2

All I did was like
$path=$_SERVER['PHP_SELF'];
 $page=basename($path);
switch("$page")

And it worked.
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

<?php
    $title = "Default Title Here";
if(1st condition){
    $title = "2nd Title";
}
if(2nd condition){
    $title = "3rd title";
}
?>
<title><?php echo $title ?></title>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100