Jump to content

Problem with $title and active menu item styling...? (newbie)


Recommended Posts

Hi am just starting to learn PHP, so this is probably a very basic mistake...

 

My PHP is Version 4.3.9, all the info (and the page I am referring to here) can be found at:

http://www.d.umn.edu/szerp001/test/test1.php

 

(I did the PHP info thing on the home page)

 

 

The problems I'm having are:

1) I can't get the $title i defined to show up in the titlebar.

 

2) I can't get the active menu link to be styled correctly, I'm trying to say that if it is active, the li element gets "id="currentpage" added to its tag, but when I view source, it never adds the tag even if the $thispage matches... ?

 

Here is the relevant code for the menu:

<ul>
<li<?php if ($thisPage=="Body1") 
      echo " id=\"currentpage\""; ?>><a href="?id=testbody">body 1</a></li>
      
<li<?php if ($thisPage=="Body2") 
      echo " id=\"currentpage\""; ?>><a href="?id=testbody2">body 2</a></li>
      
<li<?php if ($thisPage=="Home") 
      echo " id=\"currentpage\""; ?>><a href="?id=home">home</a></li>
      </ul>

 

Here is the code for a body page:

<?php $thisPage="Body1"; $title="body1"; ?>
<font face="Geneva, Arial, Helvetica, sans-serif" size="10" color="#009933">
Body 1</font>
<br />
<br /> <span id="randomtext">
this is some random text</span>

 

Here is the code for the container/template page (including the CSS):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $title; ?></title>

<style type="text/css">
ul,li {display: block; width: 100%; padding-left: 0px; list-style: none; display: inline; overflow: hidden; margin: 0; border: 0;}

#currentpage  
{display: block; width: 100%; height: 15px; background-color: #00869D; 
border-bottom: 2px solid #BECAA2;
font-size: 12px; color: #FFFFFF; 
padding-top: 9px; padding-bottom: 1px; 
text-decoration: none;}

#randomtext {font-family: 'trebuchet ms'; font-size: 13px; font-style: italic;}
</style>
</head>
<body>


<?php @ include ("testmenu.php"); ?>

<div class="body" style="float:left; width: 700px;">

<!-- get home page default -->
<?php
$default = 'home'; //Whatever default page you want to display if the file doesn't exist or you've just arrived to the home page.
$page = isset($_GET['id']) ? $_GET['id'] : $default; //Checks if ?id is set, and puts the page in and if not, it goes to the default page.
$page = basename($page); //Gets the page name only, and no directories.

include('http://www.d.umn.edu/~szerp001/test/'.$page.'.php'); //And now it's on your page!
?> 

</div>

</body>
</html>

 

 

Thank you very much for any help you can provide, I'm extremely new at this (as in, 2 days)...  :)

I do not see $thispage defined anywhere but in your menu and the body code. But if the body code is executed after the menu is included on the page, then the menu will never get the variable, as PHP is executed in a linear fashion, ie. top to bottom, left to right.

 

You're best bet would be to define the $thispage variable as the first thing on your page, before you do any of your includes.

$thisPage is defined first thing on the pages that are called into the main page (test1.php). I'm not sure how to get it there sooner?

I moved all of the code for the menu to test1.php because there wasn't really any reason for it to be separate.

 

But... the point of using $thisPage is to make the current item on the links change styles, so I can't see any other place to define it sooner?

 

Because the content page is always loaded after the container page, I'm not sure how I can fix this stuff? I mean, the container/template page is always already loaded, I guess, isn't it? So no matter what, it can't be changed by the content pages that are loading 2nd?

 

Does it not work/not meant for when only switching the content?

 

Thanks again for the help...

You have to do it like this:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<? include("required.php"); ?>

<title><?php echo $title; ?></title>

 

and then in your required, set all your variables, like $thispage and $title. You can make them dynamic (ie say $thispage = basename($_SERVER['REQUEST_URI']); ) because they are included onto the page, then executed, then stored into the variable space.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.