automatic page nav change

  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

Is it possible to use PHP code similar to following to have each page retrieving some information from a Cascading Style Sheet which would be used to change the background colour of the website navigation bar?

Code: [ Select ]
$page_handle = ltrim($_SERVER["PHP_SELF"],'/');
$page_handle = rtrim($page_handle,'.php');

$title_array = array(
  'index' => 'Index',
  'contact' => 'contact',
  'guestbook' => 'guestbook',
  'anotherpage1' => 'another1',
  'anotherpage2' => 'another2',
);

foreach ( $title_array as $a => $b ) {
if ( $page_handle == $a) {
  $page_title = "Welcome!"; }
}
}
if ( !isset($page_title) ) { $page_title = "Welcome!"; }
  1. $page_handle = ltrim($_SERVER["PHP_SELF"],'/');
  2. $page_handle = rtrim($page_handle,'.php');
  3. $title_array = array(
  4.   'index' => 'Index',
  5.   'contact' => 'contact',
  6.   'guestbook' => 'guestbook',
  7.   'anotherpage1' => 'another1',
  8.   'anotherpage2' => 'another2',
  9. );
  10. foreach ( $title_array as $a => $b ) {
  11. if ( $page_handle == $a) {
  12.   $page_title = "Welcome!"; }
  13. }
  14. }
  15. if ( !isset($page_title) ) { $page_title = "Welcome!"; }


If it is possible, could someone inform me on how i would go about achieving this?

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Are you trying to make it so when your visiting a page the navigation background color changes?

Example:

http://wazzutke.com
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

I am actually not seeing any changes in that, but i believe you understand me.

The site i am currently working on - http://www.campbell-james.co.uk/new/template.php - is built up where i have php code including 2 pages on the each page. The first page builds up the first half of the site code and the second page builds up the second half. I figured this made alot of sense for creating a site that will eventually have a large quantity of pages.

Because of the way the site has been designed, the intention was to have the blue navigation area to change colour on every page it loads up. That is what i had hoped to do and i figured that it would be possible to do using similar code to the one i posted above.
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

I also wondered if there was any way of having an image to open up from a folder for each page using the same sort of code above?

I thought it would be relatively easy to figure out, but my knowledge of PHP isn't as vast as i would prefer.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Okay, so you want the blue area to change colors depending on what page is being view. Correct?

Your current code is on the right track. What I would suggest is create an array of your pages.

PHP Code: [ Select ]
$page_name = basename($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
 
$myPages = array(
   'pageName'=>'styleClass',
   'pageName'=>'styleClass',
   'pageName'=>'styleClass',
   'pageName'=>'styleClass'
        );
 
$use_style = $myPages[$page_name];
  1. $page_name = basename($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
  2.  
  3. $myPages = array(
  4.    'pageName'=>'styleClass',
  5.    'pageName'=>'styleClass',
  6.    'pageName'=>'styleClass',
  7.    'pageName'=>'styleClass'
  8.         );
  9.  
  10. $use_style = $myPages[$page_name];


I would then create style classes or id's if for each page. You could even just use colors.

Code: [ Select ]
'pageName'=>'blue',


CSS Code: [ Select ]
.blue {
background-color: #0000FF;
}
  1. .blue {
  2. background-color: #0000FF;
  3. }
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

Thanks Spoof.

What i am unsure of here though is how would i make that be specific to just the navigation bar?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

For your menu, I would add a class to it.

PHP Code: [ Select ]
<div id="menu" class="<?=$use_style?>">


Use that style to apply the color.

To limit the style to only work with the menu:
CSS Code: [ Select ]
div#menu.color1
{
   background-color:#f00;
}
  1. div#menu.color1
  2. {
  3.    background-color:#f00;
  4. }
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Here is a quick example I made.

Code: [ Select ]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>James Campbell Architects - Welcome!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<meta name="description" content="www.campbell-james.co.uk - James Campbell Architects" >
<meta name="keywords" content="James Campbell Architects, James, Campbell, Architects, Aberdeen, Scotland, Inverurie, Environmental" >
<meta name="robots" content="index,follow" >
<link rel="shortcut icon" href="http://www.campbell-james.co.uk/new/images/favicon.ico" >
<link rel="stylesheet" href="http://www.campbell-james.co.uk/new/style.css" >

<style type="text/css">

div#menu.style1
{
    background-color:#f00;
}
div#menu.style2
{
    background-color:#0f0;
}
div#menu.style3
{
    background-color:#00f;
}

</style>

</head>

<?php

$page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
$page_name = $page_name['filename'];


$myPages = array(
  'pageName1'=>'style1',
  'pageName2'=>'style2',
  'pageName3'=>'style3'
    );

$use_style = $myPages[$page_name];

?>

<body>

<div id="menu" class="<?=$use_style?>">
    <ul id="qm0" class="qmmc">
        <li><a class="qmparent" href="index.php">Home</a></li>
        <li><a class="qmparent" href="index.php">Home</a></li>
        <li><a class="qmparent" href="index.php">Home</a></li>
        <li><a class="qmparent" href="index.php">Home</a></li>
        <li><a class="qmparent" href="index.php">Home</a></li>
        <li><a class="qmparent" href="index.php">Home</a></li>
        <li><a class="qmparent" href="index.php">Home</a></li>
    </ul>

</div>
</body>
</html>
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2.      "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>James Campbell Architects - Welcome!</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
  7. <meta name="description" content="www.campbell-james.co.uk - James Campbell Architects" >
  8. <meta name="keywords" content="James Campbell Architects, James, Campbell, Architects, Aberdeen, Scotland, Inverurie, Environmental" >
  9. <meta name="robots" content="index,follow" >
  10. <link rel="shortcut icon" href="http://www.campbell-james.co.uk/new/images/favicon.ico" >
  11. <link rel="stylesheet" href="http://www.campbell-james.co.uk/new/style.css" >
  12. <style type="text/css">
  13. div#menu.style1
  14. {
  15.     background-color:#f00;
  16. }
  17. div#menu.style2
  18. {
  19.     background-color:#0f0;
  20. }
  21. div#menu.style3
  22. {
  23.     background-color:#00f;
  24. }
  25. </style>
  26. </head>
  27. <?php
  28. $page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
  29. $page_name = $page_name['filename'];
  30. $myPages = array(
  31.   'pageName1'=>'style1',
  32.   'pageName2'=>'style2',
  33.   'pageName3'=>'style3'
  34.     );
  35. $use_style = $myPages[$page_name];
  36. ?>
  37. <body>
  38. <div id="menu" class="<?=$use_style?>">
  39.     <ul id="qm0" class="qmmc">
  40.         <li><a class="qmparent" href="index.php">Home</a></li>
  41.         <li><a class="qmparent" href="index.php">Home</a></li>
  42.         <li><a class="qmparent" href="index.php">Home</a></li>
  43.         <li><a class="qmparent" href="index.php">Home</a></li>
  44.         <li><a class="qmparent" href="index.php">Home</a></li>
  45.         <li><a class="qmparent" href="index.php">Home</a></li>
  46.         <li><a class="qmparent" href="index.php">Home</a></li>
  47.     </ul>
  48. </div>
  49. </body>
  50. </html>


One thing is you have to remove the background-color attribute from your #menu the class wont over right it.

Also notice I changed how I get the file name.
PHP Code: [ Select ]
$page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
$page_name = $page_name['filename'];
  1. $page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
  2. $page_name = $page_name['filename'];
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

Thanks Spoof.

I am actually having trouble with the CSS on the navigation bar which is causing the problems.

Your help has been really appreciated. Given a bit more time i'll have the rest of it sussed i hope.

Thank you very much.
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

Okay, so here is what i've got...

Code: [ Select ]
$page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
$page_name = $page_name['filename'];
$myPages = array(
 'new/index'=>'blue',
 'pageName2'=>'style2',
 'pageName3'=>'style3'
  );
$use_style = $myPages[$page_name];
  1. $page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
  2. $page_name = $page_name['filename'];
  3. $myPages = array(
  4.  'new/index'=>'blue',
  5.  'pageName2'=>'style2',
  6.  'pageName3'=>'style3'
  7.   );
  8. $use_style = $myPages[$page_name];


In my index.php page. Below that in the navigation i have...

Code: [ Select ]
<div id="menu" class="<?=$use_style?>">
  <ul id="qm0" class="qmmc">
   <li><a class="qmparent" href="index.php">Home</a> <br />
   <li><a class="qmparent" href="javascript:void(0)">Architectural Services</a>
    <ul>
     <li><a href="/community.php">Community</a></li>
     <li><a href="residential.php">Residential</a></li>
     <li><a href="social.php">Social Housing</a></li>
     <li><a href="industrial.php">Industrial</a></li>
     <li><a href="leisure.php">Leisure</a></li>
     <li><a href="commercial.php">Commercial</a></li>
     <li><a href="education.php">Education</a></li>
     <li><a href="health.php">Health</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Environmental Services</a>
    <ul>
     <li><a href="energydesign.php">Energy Design</a></li>
     <li><a href="nher.php">NHER, SAP</a></li>
     <li><a href="epc.php">EPCs, OCDEA</a></li>
     <li><a href="carbontrust.php">Carbon Trust</a></li>
     <li><a href="designadvice.php">Design Advice</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Other Services</a>
    <ul>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Resources & Links</a>
    <ul>
     <li><a href="http://www.architecture.com" target="_new">RIBA</a></li>
     <li><a href="http://www.rias.org.uk" target="_new">RIAS</a></li>
     <li><a href="http://www.carbontrust.co.uk" target="_new">Carbon Trust</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Contact Us</a>
   <li class="qmclear"></li>
  </ul>
  1. <div id="menu" class="<?=$use_style?>">
  2.   <ul id="qm0" class="qmmc">
  3.    <li><a class="qmparent" href="index.php">Home</a> <br />
  4.    <li><a class="qmparent" href="javascript:void(0)">Architectural Services</a>
  5.     <ul>
  6.      <li><a href="/community.php">Community</a></li>
  7.      <li><a href="residential.php">Residential</a></li>
  8.      <li><a href="social.php">Social Housing</a></li>
  9.      <li><a href="industrial.php">Industrial</a></li>
  10.      <li><a href="leisure.php">Leisure</a></li>
  11.      <li><a href="commercial.php">Commercial</a></li>
  12.      <li><a href="education.php">Education</a></li>
  13.      <li><a href="health.php">Health</a></li>
  14.     </ul>
  15.    </li>
  16.    <br />
  17.    <li><a class="qmparent" href="javascript:void(0)">Environmental Services</a>
  18.     <ul>
  19.      <li><a href="energydesign.php">Energy Design</a></li>
  20.      <li><a href="nher.php">NHER, SAP</a></li>
  21.      <li><a href="epc.php">EPCs, OCDEA</a></li>
  22.      <li><a href="carbontrust.php">Carbon Trust</a></li>
  23.      <li><a href="designadvice.php">Design Advice</a></li>
  24.     </ul>
  25.    </li>
  26.    <br />
  27.    <li><a class="qmparent" href="javascript:void(0)">Other Services</a>
  28.     <ul>
  29.      <li><a href="javascript:void(0)">Sub menu</a></li>
  30.      <li><a href="javascript:void(0)">Sub menu</a></li>
  31.      <li><a href="javascript:void(0)">Sub menu</a></li>
  32.      <li><a href="javascript:void(0)">Sub menu</a></li>
  33.      <li><a href="javascript:void(0)">Sub menu</a></li>
  34.     </ul>
  35.    </li>
  36.    <br />
  37.    <li><a class="qmparent" href="javascript:void(0)">Resources & Links</a>
  38.     <ul>
  39.      <li><a href="http://www.architecture.com" target="_new">RIBA</a></li>
  40.      <li><a href="http://www.rias.org.uk" target="_new">RIAS</a></li>
  41.      <li><a href="http://www.carbontrust.co.uk" target="_new">Carbon Trust</a></li>
  42.     </ul>
  43.    </li>
  44.    <br />
  45.    <li><a class="qmparent" href="javascript:void(0)">Contact Us</a>
  46.    <li class="qmclear"></li>
  47.   </ul>


In the CSS i have...

Code: [ Select ]
div#menu.blue
{
  background-color:#000000;
}
div#menu.style2
{
  background-color:#0f0;
}
div#menu.style3
{
  background-color:#00f;
}
  1. div#menu.blue
  2. {
  3.   background-color:#000000;
  4. }
  5. div#menu.style2
  6. {
  7.   background-color:#0f0;
  8. }
  9. div#menu.style3
  10. {
  11.   background-color:#00f;
  12. }


I removed the background colour in the menu part.

It appears as though the php page is not recognising the CSS code from the CSS sheet i have. The current CSS code is done on a seperate css page.

Not entirely sure what is actually going wrong here as i have done everthing you mention.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

I would first check to see if $page_name is what your expecting it to be. Add a echo or print to see what its being set to. You could also just check your source and see what style name is being printed for the class. If its printing the correct class then its a problem with the css.

To trouble shoot the css I would remove the div#menu and make the class global.
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

:lol:

I am well and truly lost here. Way out of my depth.

Been looking at this problem for a short while today and having no luck at all.

Your help has been great Spoof, so i appreciate this. I have a feeling it is all got something to do with the way the site has been built, although i cannot work out why. I am running out of hair to pull out! :evil:
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Your server might not support PHP short code. I looked at your source and some of the PHP is not being recognized.

Code: [ Select ]
<div id="image">
 <div align="right"></div>
</div>

<div id="menu" class="<?=$use_style?>">
  <ul id="qm0" class="qmmc">
  1. <div id="image">
  2.  <div align="right"></div>
  3. </div>
  4. <div id="menu" class="<?=$use_style?>">
  5.   <ul id="qm0" class="qmmc">


You might have to to do something like this:

Code: [ Select ]
<div id="image">
 <div align="right"></div>
</div>

<div id="menu" class="<?php echo $use_style; ?>">
  <ul id="qm0" class="qmmc">
  1. <div id="image">
  2.  <div align="right"></div>
  3. </div>
  4. <div id="menu" class="<?php echo $use_style; ?>">
  5.   <ul id="qm0" class="qmmc">
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

Thanks. Still no luck at all.

I was slightly reluctant to post the full code here, but if there is any way someone can figure out what may be causing the issue then i would be extremely grateful.

Like i said the site is built up using 2 main documents to build the general layout of the site. This is the first part of the page which i have changed for ozzu purpose only to "include1"

Code: [ Select ]
<?php
// Prevent users from looking at this include file directly
if ( strpos($_SERVER["PHP_SELF"],"include1.php") !== false ) {
  header ('Location:index.php');
  exit();
}
else {
// Automate page titles
$page_handle = ltrim($_SERVER["PHP_SELF"],'/');
$page_handle = rtrim($page_handle,'.php');

$title_array = array(
  'new/index' => 'blablabla',
  'contact' => 'contact',
  'environmental' => 'environmental',
    'anotherpage1' => 'another1',
    'anotherpage2' => 'another2',
);

foreach ( $title_array as $a => $b ) {
if ( $page_handle == $a) {
  $page_title = $b;
}
}
if ( !isset($page_title) ) { $page_title = "Welcome!"; }

// The following code determines what colour the navigation bar backdrop is depending on each page.

$page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
$page_name = $page_name['filename'];
$myPages = array(
 'new/index'=>'color1',
 'pageName2'=>'style2',
 'pageName3'=>'style3'
  );
$use_style = $myPages[$page_name];

// Init the date
$gmttime = time() + (5 * 60 * 60);

echo ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>James Campbell Architects - '. $page_title .'</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<meta name="description" content="www.campbell-james.co.uk - James Campbell Architects" >
<meta name="keywords" content="James Campbell Architects, James, Campbell, Architects, Aberdeen, Scotland, Inverurie, Environmental" >
<meta name="robots" content="index,follow" >
<link rel="shortcut icon" href="http://www.campbell-james.co.uk/new/images/favicon.ico" >
<link rel="stylesheet" href="style.css" >

<style type="text/css">
.color1
{
  background-color:#f00;
}
.color2
{
  background-color:#0f0;
}
.color3
{
  background-color:#00f;
}
</style>

</head>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-412299-3";
urchinTracker();
</script>

<script type="text/javascript">
<!--
function delayer(){
  window.location = "../index.php"
}
//-->
</script>

<body>
<div id="page_container">

<div id="banner">
 <p>&nbsp;</p>
 <p> <img src="title3.png" width="1060" height="100" align="bottom" /></p>
</div>

<div id="image">
 <div align="right"></div>
</div>

<div id="menu" class="<?php echo $use_style; ?>">
 <ul id="qm0" class="qmmc">
   <li><a class="qmparent" href="index.php">Home</a> <br />
   <li><a class="qmparent" href="javascript:void(0)">Architectural Services</a>
    <ul>
     <li><a href="/community.php">Community</a></li>
     <li><a href="residential.php">Residential</a></li>
     <li><a href="social.php">Social Housing</a></li>
     <li><a href="industrial.php">Industrial</a></li>
     <li><a href="leisure.php">Leisure</a></li>
     <li><a href="commercial.php">Commercial</a></li>
     <li><a href="education.php">Education</a></li>
     <li><a href="health.php">Health</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Environmental Services</a>
    <ul>
     <li><a href="energydesign.php">Energy Design</a></li>
     <li><a href="nher.php">NHER, SAP</a></li>
     <li><a href="epc.php">EPCs, OCDEA</a></li>
     <li><a href="carbontrust.php">Carbon Trust</a></li>
     <li><a href="designadvice.php">Design Advice</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Other Services</a>
    <ul>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
     <li><a href="javascript:void(0)">Sub menu</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Resources & Links</a>
    <ul>
     <li><a href="http://www.architecture.com" target="_new">RIBA</a></li>
     <li><a href="http://www.rias.org.uk" target="_new">RIAS</a></li>
     <li><a href="http://www.carbontrust.co.uk" target="_new">Carbon Trust</a></li>
    </ul>
   </li>
   <br />
   <li><a class="qmparent" href="javascript:void(0)">Contact Us</a>
   <li class="qmclear"></li>
  </ul>

<p><script type="text/javascript">qm_create(0,true,0,500,false,false,false,false,false);</script>
</p>
</div>
<div id="quote">
 <div align="center">
  <p><img src="quotation.jpg" align="top" /></p>
  </div>
</div>
<div id="content">
');
}

?>
  1. <?php
  2. // Prevent users from looking at this include file directly
  3. if ( strpos($_SERVER["PHP_SELF"],"include1.php") !== false ) {
  4.   header ('Location:index.php');
  5.   exit();
  6. }
  7. else {
  8. // Automate page titles
  9. $page_handle = ltrim($_SERVER["PHP_SELF"],'/');
  10. $page_handle = rtrim($page_handle,'.php');
  11. $title_array = array(
  12.   'new/index' => 'blablabla',
  13.   'contact' => 'contact',
  14.   'environmental' => 'environmental',
  15.     'anotherpage1' => 'another1',
  16.     'anotherpage2' => 'another2',
  17. );
  18. foreach ( $title_array as $a => $b ) {
  19. if ( $page_handle == $a) {
  20.   $page_title = $b;
  21. }
  22. }
  23. if ( !isset($page_title) ) { $page_title = "Welcome!"; }
  24. // The following code determines what colour the navigation bar backdrop is depending on each page.
  25. $page_name = pathinfo($_SERVER['PHP_SELF']); // This will return the PHP file name of the current file
  26. $page_name = $page_name['filename'];
  27. $myPages = array(
  28.  'new/index'=>'color1',
  29.  'pageName2'=>'style2',
  30.  'pageName3'=>'style3'
  31.   );
  32. $use_style = $myPages[$page_name];
  33. // Init the date
  34. $gmttime = time() + (5 * 60 * 60);
  35. echo ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  36.      "http://www.w3.org/TR/html4/loose.dtd">
  37. <html>
  38. <head>
  39. <title>James Campbell Architects - '. $page_title .'</title>
  40. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
  41. <meta name="description" content="www.campbell-james.co.uk - James Campbell Architects" >
  42. <meta name="keywords" content="James Campbell Architects, James, Campbell, Architects, Aberdeen, Scotland, Inverurie, Environmental" >
  43. <meta name="robots" content="index,follow" >
  44. <link rel="shortcut icon" href="http://www.campbell-james.co.uk/new/images/favicon.ico" >
  45. <link rel="stylesheet" href="style.css" >
  46. <style type="text/css">
  47. .color1
  48. {
  49.   background-color:#f00;
  50. }
  51. .color2
  52. {
  53.   background-color:#0f0;
  54. }
  55. .color3
  56. {
  57.   background-color:#00f;
  58. }
  59. </style>
  60. </head>
  61. <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
  62. </script>
  63. <script type="text/javascript">
  64. _uacct = "UA-412299-3";
  65. urchinTracker();
  66. </script>
  67. <script type="text/javascript">
  68. <!--
  69. function delayer(){
  70.   window.location = "../index.php"
  71. }
  72. //-->
  73. </script>
  74. <body>
  75. <div id="page_container">
  76. <div id="banner">
  77.  <p>&nbsp;</p>
  78.  <p> <img src="title3.png" width="1060" height="100" align="bottom" /></p>
  79. </div>
  80. <div id="image">
  81.  <div align="right"></div>
  82. </div>
  83. <div id="menu" class="<?php echo $use_style; ?>">
  84.  <ul id="qm0" class="qmmc">
  85.    <li><a class="qmparent" href="index.php">Home</a> <br />
  86.    <li><a class="qmparent" href="javascript:void(0)">Architectural Services</a>
  87.     <ul>
  88.      <li><a href="/community.php">Community</a></li>
  89.      <li><a href="residential.php">Residential</a></li>
  90.      <li><a href="social.php">Social Housing</a></li>
  91.      <li><a href="industrial.php">Industrial</a></li>
  92.      <li><a href="leisure.php">Leisure</a></li>
  93.      <li><a href="commercial.php">Commercial</a></li>
  94.      <li><a href="education.php">Education</a></li>
  95.      <li><a href="health.php">Health</a></li>
  96.     </ul>
  97.    </li>
  98.    <br />
  99.    <li><a class="qmparent" href="javascript:void(0)">Environmental Services</a>
  100.     <ul>
  101.      <li><a href="energydesign.php">Energy Design</a></li>
  102.      <li><a href="nher.php">NHER, SAP</a></li>
  103.      <li><a href="epc.php">EPCs, OCDEA</a></li>
  104.      <li><a href="carbontrust.php">Carbon Trust</a></li>
  105.      <li><a href="designadvice.php">Design Advice</a></li>
  106.     </ul>
  107.    </li>
  108.    <br />
  109.    <li><a class="qmparent" href="javascript:void(0)">Other Services</a>
  110.     <ul>
  111.      <li><a href="javascript:void(0)">Sub menu</a></li>
  112.      <li><a href="javascript:void(0)">Sub menu</a></li>
  113.      <li><a href="javascript:void(0)">Sub menu</a></li>
  114.      <li><a href="javascript:void(0)">Sub menu</a></li>
  115.      <li><a href="javascript:void(0)">Sub menu</a></li>
  116.     </ul>
  117.    </li>
  118.    <br />
  119.    <li><a class="qmparent" href="javascript:void(0)">Resources & Links</a>
  120.     <ul>
  121.      <li><a href="http://www.architecture.com" target="_new">RIBA</a></li>
  122.      <li><a href="http://www.rias.org.uk" target="_new">RIAS</a></li>
  123.      <li><a href="http://www.carbontrust.co.uk" target="_new">Carbon Trust</a></li>
  124.     </ul>
  125.    </li>
  126.    <br />
  127.    <li><a class="qmparent" href="javascript:void(0)">Contact Us</a>
  128.    <li class="qmclear"></li>
  129.   </ul>
  130. <p><script type="text/javascript">qm_create(0,true,0,500,false,false,false,false,false);</script>
  131. </p>
  132. </div>
  133. <div id="quote">
  134.  <div align="center">
  135.   <p><img src="quotation.jpg" align="top" /></p>
  136.   </div>
  137. </div>
  138. <div id="content">
  139. ');
  140. }
  141. ?>


The other pages don't appear to be relevant for the problem at hand. I will though add the full CSS, even though i doubt it adds much more to what i have previously posted...

Code: [ Select ]
.qmmc .qmdivider{display:block;font-size:1px;border-width:0px;border-style:solid;position:relative;z-index:1;}.qmmc .qmdividery{float:left;width:0px;}.qmmc .qmtitle{display:block;cursor:default;white-space:nowrap;position:relative;z-index:1;}.qmclear {font-size:1px;height:0px;width:0px;clear:left;line-height:0px;display:block;float:none !important;}.qmmc {position:relative;zoom:1;z-index:10;}.qmmc a, .qmmc li {float:left;display:block;white-space:nowrap;position:relative;z-index:1;}.qmmc div a, .qmmc ul a, .qmmc ul li {float:none;}.qmsh div a {float:left;}.qmmc div{visibility:hidden;position:absolute;}.qmmc li {z-index:auto;}.qmmc ul {left:-10000px;position:absolute;z-index:10;}.qmmc, .qmmc ul {list-style:none;padding:0px;margin:0px;}.qmmc li a {float:none}.qmmc li:hover>ul{left:auto;}#qm0 li {float:none;}#qm0 li:hover>ul{top:0px;left:100%;}

    #qm0    
    {
    width:160px;
    height: 302px;
    padding:0px 20px;
    margin-top:20px;
    background-color:transparent;
    border-width:0px;
    border-style:solid;
    border-color:#006699;
    }


    #qm0 a    
    {
    padding:3px 20px 3px 3px;
    background-color:transparent;
    color:#aaaaaa;
    font-family:Arial;
    font-size:12px;
    text-decoration:none;
    border-width:0px 0px 1px;
    border-style:solid;
    border-color:#aaaaaa;
    }


    #qm0 a:hover    
    {    
        color:#ffffff;
        border-color:#fff;
    }


    body #qm0 .qmactive, body #qm0 .qmactive:hover    
    {    
        color:#ffffff;
        border-color:#006699;
    }


    #qm0 div, #qm0 ul    
    {    
        padding:5px;
        background-color:transparent;
        border-width:0px;
        border-style:solid;
        border-color:#fff;
    }


    #qm0 div a, #qm0 ul a    
    {    
        padding:3px 20px 3px 5px;
        color: #cccccc;
        font-size:12px;
        border-width:0px;
        border-color:#fff;
    }


    #qm0 div a:hover, #qm0 ul a:hover    
    {    
        color:#fff;
        text-decoration:underline;
    }


    body #qm0 div .qmactive, body #qm0 div .qmactive:hover    
    {    
        color:#006699;
        text-decoration:underline;
    }

body {
    background-color:    #fff;
    font-family:Arial, Helvetica, sans-serif;
    font-size:16px;
    padding:0;
    margin:0;
}

div{
    margin:0;
    padding:0;
    /*width: 1060px;*/
    padding-right: 0px;
}
h1{margin:0;padding:0;}
h2{margin:0;padding:0;}
h3{margin:0;padding:0;}
p{
    margin:0;
    padding:0;
}
ul{margin:0;padding:0;}
li{list-style-type:none;}

#page_container{
    width:1060px;
    margin:0 auto;
}
#banner{
    background-color: #000;
    background-image: url(images/bannergrad.jpg);
    background-repeat: repeat-x;
    height:125px;
    padding-left: 0px;
}
#menu{
    width:300px;
    height:302px;
    float:none;
    padding-left:20px;
    padding-top:10px;
}


div#menu.color1
{
  background-color:#f00;
}


#image{
    background:#ECECEC;
    background-image: url(images/index.jpg);
    background-position:right;
    float:right;
    height: 312px;
    width: 740px;
}
#quote{
    background:#fff;
    height:55px;
    width:970px;
    border-top: 0px solid #000;
    border-bottom: 0px solid #000;
    padding-left: 40px;
    padding-top: 20px;
    padding-bottom: 20px;
}
    
#left_column{
    background:#ddd;
    width:550px;
    height:500px;
    float: left;
    padding-top: 50px;
    padding-left: 30px;
    padding-right: 30px;
    color: #006699
        
}

#right_column{
    background-color:#ccc;
    width:390px;
    height:500px;
    float: left;
    padding-top: 50px;
    padding-left: 30px;
    padding-right: 30px;
}

#mainbox{
    background:#ddd;
    width:960px;
    height:500px;
    float: left;
    padding-top: 50px;
    padding-left: 50px;
    padding-right: 50px;
    color: #006699
        
}

#footer{
    background-color: #000000;
    background-image: url(images/footer.jpg);
    background-repeat: repeat-x;
    height:30px;
    padding-left: 0px;
}

A:link {text-decoration: none;color:#fff;}
A:visited {text-decoration: none;color:#fff;}
A:active {text-decoration: none;color:#fff;}
A:hover {text-decoration: none; color:#ccc;}

.style1 {
    font-size: 12px
}

.style2 {
    font-size: 12px; color: #000000;
}

.style3 {
color: #000000;
}
  1. .qmmc .qmdivider{display:block;font-size:1px;border-width:0px;border-style:solid;position:relative;z-index:1;}.qmmc .qmdividery{float:left;width:0px;}.qmmc .qmtitle{display:block;cursor:default;white-space:nowrap;position:relative;z-index:1;}.qmclear {font-size:1px;height:0px;width:0px;clear:left;line-height:0px;display:block;float:none !important;}.qmmc {position:relative;zoom:1;z-index:10;}.qmmc a, .qmmc li {float:left;display:block;white-space:nowrap;position:relative;z-index:1;}.qmmc div a, .qmmc ul a, .qmmc ul li {float:none;}.qmsh div a {float:left;}.qmmc div{visibility:hidden;position:absolute;}.qmmc li {z-index:auto;}.qmmc ul {left:-10000px;position:absolute;z-index:10;}.qmmc, .qmmc ul {list-style:none;padding:0px;margin:0px;}.qmmc li a {float:none}.qmmc li:hover>ul{left:auto;}#qm0 li {float:none;}#qm0 li:hover>ul{top:0px;left:100%;}
  2.     #qm0    
  3.     {
  4.     width:160px;
  5.     height: 302px;
  6.     padding:0px 20px;
  7.     margin-top:20px;
  8.     background-color:transparent;
  9.     border-width:0px;
  10.     border-style:solid;
  11.     border-color:#006699;
  12.     }
  13.     #qm0 a    
  14.     {
  15.     padding:3px 20px 3px 3px;
  16.     background-color:transparent;
  17.     color:#aaaaaa;
  18.     font-family:Arial;
  19.     font-size:12px;
  20.     text-decoration:none;
  21.     border-width:0px 0px 1px;
  22.     border-style:solid;
  23.     border-color:#aaaaaa;
  24.     }
  25.     #qm0 a:hover    
  26.     {    
  27.         color:#ffffff;
  28.         border-color:#fff;
  29.     }
  30.     body #qm0 .qmactive, body #qm0 .qmactive:hover    
  31.     {    
  32.         color:#ffffff;
  33.         border-color:#006699;
  34.     }
  35.     #qm0 div, #qm0 ul    
  36.     {    
  37.         padding:5px;
  38.         background-color:transparent;
  39.         border-width:0px;
  40.         border-style:solid;
  41.         border-color:#fff;
  42.     }
  43.     #qm0 div a, #qm0 ul a    
  44.     {    
  45.         padding:3px 20px 3px 5px;
  46.         color: #cccccc;
  47.         font-size:12px;
  48.         border-width:0px;
  49.         border-color:#fff;
  50.     }
  51.     #qm0 div a:hover, #qm0 ul a:hover    
  52.     {    
  53.         color:#fff;
  54.         text-decoration:underline;
  55.     }
  56.     body #qm0 div .qmactive, body #qm0 div .qmactive:hover    
  57.     {    
  58.         color:#006699;
  59.         text-decoration:underline;
  60.     }
  61. body {
  62.     background-color:    #fff;
  63.     font-family:Arial, Helvetica, sans-serif;
  64.     font-size:16px;
  65.     padding:0;
  66.     margin:0;
  67. }
  68. div{
  69.     margin:0;
  70.     padding:0;
  71.     /*width: 1060px;*/
  72.     padding-right: 0px;
  73. }
  74. h1{margin:0;padding:0;}
  75. h2{margin:0;padding:0;}
  76. h3{margin:0;padding:0;}
  77. p{
  78.     margin:0;
  79.     padding:0;
  80. }
  81. ul{margin:0;padding:0;}
  82. li{list-style-type:none;}
  83. #page_container{
  84.     width:1060px;
  85.     margin:0 auto;
  86. }
  87. #banner{
  88.     background-color: #000;
  89.     background-image: url(images/bannergrad.jpg);
  90.     background-repeat: repeat-x;
  91.     height:125px;
  92.     padding-left: 0px;
  93. }
  94. #menu{
  95.     width:300px;
  96.     height:302px;
  97.     float:none;
  98.     padding-left:20px;
  99.     padding-top:10px;
  100. }
  101. div#menu.color1
  102. {
  103.   background-color:#f00;
  104. }
  105. #image{
  106.     background:#ECECEC;
  107.     background-image: url(images/index.jpg);
  108.     background-position:right;
  109.     float:right;
  110.     height: 312px;
  111.     width: 740px;
  112. }
  113. #quote{
  114.     background:#fff;
  115.     height:55px;
  116.     width:970px;
  117.     border-top: 0px solid #000;
  118.     border-bottom: 0px solid #000;
  119.     padding-left: 40px;
  120.     padding-top: 20px;
  121.     padding-bottom: 20px;
  122. }
  123.     
  124. #left_column{
  125.     background:#ddd;
  126.     width:550px;
  127.     height:500px;
  128.     float: left;
  129.     padding-top: 50px;
  130.     padding-left: 30px;
  131.     padding-right: 30px;
  132.     color: #006699
  133.         
  134. }
  135. #right_column{
  136.     background-color:#ccc;
  137.     width:390px;
  138.     height:500px;
  139.     float: left;
  140.     padding-top: 50px;
  141.     padding-left: 30px;
  142.     padding-right: 30px;
  143. }
  144. #mainbox{
  145.     background:#ddd;
  146.     width:960px;
  147.     height:500px;
  148.     float: left;
  149.     padding-top: 50px;
  150.     padding-left: 50px;
  151.     padding-right: 50px;
  152.     color: #006699
  153.         
  154. }
  155. #footer{
  156.     background-color: #000000;
  157.     background-image: url(images/footer.jpg);
  158.     background-repeat: repeat-x;
  159.     height:30px;
  160.     padding-left: 0px;
  161. }
  162. A:link {text-decoration: none;color:#fff;}
  163. A:visited {text-decoration: none;color:#fff;}
  164. A:active {text-decoration: none;color:#fff;}
  165. A:hover {text-decoration: none; color:#ccc;}
  166. .style1 {
  167.     font-size: 12px
  168. }
  169. .style2 {
  170.     font-size: 12px; color: #000000;
  171. }
  172. .style3 {
  173. color: #000000;
  174. }


If anyone would be able to figure out anything that may help me then i would be very grateful.

Thanks again SpooF.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Your problem looks to be in your $page_name array. The method I supplied to get the name of the current page does not return the directory.

For example. If your page was located at http://yoursite.com/new/page.php the following would be true:

$page_handle = 'new/page'
$page_name = 'page'

So for your $page_name you can either change the key value to not include the directory or you can use the $page_handle variable as your lookup key.

I see benefits to both.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

I don't know if this was answered adequately, but I think I have a better way to come about this after reading the first four posts.

Here is how I would do it... (The code looks a lot better if you download it and open it with Notepad or Notepad++ or something).

PHP Code: [ Select ]
<?php
// Page name
$page_name = ltrim($_SERVER["PHP_SELF"],'/');
$page_name = rtrim($page_name,'.php');
 
// Default footer text
$footer = '© 2010 Melted, LLC';
 
/*
    The pages...
   
    You could have different things for different pages...
    like what I got going with 'css' and 'title' for each page.
   
    That could be useful for things like javascript and other things
    that are page specific or things that other pages just don't need.
   
    I'm expecting here that each page would have it's own CSS and title
    element, so I coded in the process after the array that processes
    those things. If you are going to have something that is page
    specific and wouldn't be defined or neccessary to define elsewhere,
    you could use a conditional statement like I did with 'footer' and
    'image'.
*/
$pages = array(
            'index' => array('css' => '#div_name' => array('background-color' => '#fc0000',
                                                           'font-color' => '#000000'
                                                         ),
                                      'div[class].active_pages' => array('float' => 'right'
                                                         ),
                             'title' => 'Page Title for Index'
                            ),
            'contact'   => array('css' => 'p' => array('background-color' => '#fc0000',
                                                       'font-color' => '#000000'
                                                         ),
                                 'title' => 'Page Title for Contact',
                                 'image' => '<img src="path/to/img.png" alt="An image" />' // This would be written into the HTML part of the code... no need for additional PHP
                                ),
            'guestbook' => array('css' => 'span#name' => array('background-color' => '#fc0000',
                                                               'font-color' => '#000000'
                                                         ),
                                 'title' => 'Page Title for Guestbook',
                                 'footer' => 'Driven by Bigwebmaster © 2010 Bigwebmaster.com',
                                )
);
 
// Getting the page title for the pages
$page_title = (isset($pages[$page_name]['title'])) ? $pages[$page_name]['title'] : 'Welcome';
 
// Generating the CSS for this page
$css = null;
foreach($pages[$page_name]['css'] as $css_element => $css_components)
{
    $css .= $css_element . ' {\n';
    foreach($css_components as $css_rule => $css_value)
    {
        $css .= "     {$css_rule}: {$css_value};\n";
    }
    $css .= '}\n\n';
}
$css = trim($css);
 
// Generating the footer
$footer = (isset($pages[$page_name]['footer'])) ? $pages[$page_name]['footer'] : $footer;
 
?>
  1. <?php
  2. // Page name
  3. $page_name = ltrim($_SERVER["PHP_SELF"],'/');
  4. $page_name = rtrim($page_name,'.php');
  5.  
  6. // Default footer text
  7. $footer = '© 2010 Melted, LLC';
  8.  
  9. /*
  10.     The pages...
  11.    
  12.     You could have different things for different pages...
  13.     like what I got going with 'css' and 'title' for each page.
  14.    
  15.     That could be useful for things like javascript and other things
  16.     that are page specific or things that other pages just don't need.
  17.    
  18.     I'm expecting here that each page would have it's own CSS and title
  19.     element, so I coded in the process after the array that processes
  20.     those things. If you are going to have something that is page
  21.     specific and wouldn't be defined or neccessary to define elsewhere,
  22.     you could use a conditional statement like I did with 'footer' and
  23.     'image'.
  24. */
  25. $pages = array(
  26.             'index' => array('css' => '#div_name' => array('background-color' => '#fc0000',
  27.                                                            'font-color' => '#000000'
  28.                                                          ),
  29.                                       'div[class].active_pages' => array('float' => 'right'
  30.                                                          ),
  31.                              'title' => 'Page Title for Index'
  32.                             ),
  33.             'contact'   => array('css' => 'p' => array('background-color' => '#fc0000',
  34.                                                        'font-color' => '#000000'
  35.                                                          ),
  36.                                  'title' => 'Page Title for Contact',
  37.                                  'image' => '<img src="path/to/img.png" alt="An image" />' // This would be written into the HTML part of the code... no need for additional PHP
  38.                                 ),
  39.             'guestbook' => array('css' => 'span#name' => array('background-color' => '#fc0000',
  40.                                                                'font-color' => '#000000'
  41.                                                          ),
  42.                                  'title' => 'Page Title for Guestbook',
  43.                                  'footer' => 'Driven by Bigwebmaster © 2010 Bigwebmaster.com',
  44.                                 )
  45. );
  46.  
  47. // Getting the page title for the pages
  48. $page_title = (isset($pages[$page_name]['title'])) ? $pages[$page_name]['title'] : 'Welcome';
  49.  
  50. // Generating the CSS for this page
  51. $css = null;
  52. foreach($pages[$page_name]['css'] as $css_element => $css_components)
  53. {
  54.     $css .= $css_element . ' {\n';
  55.     foreach($css_components as $css_rule => $css_value)
  56.     {
  57.         $css .= "     {$css_rule}: {$css_value};\n";
  58.     }
  59.     $css .= '}\n\n';
  60. }
  61. $css = trim($css);
  62.  
  63. // Generating the footer
  64. $footer = (isset($pages[$page_name]['footer'])) ? $pages[$page_name]['footer'] : $footer;
  65.  
  66. ?>


I don't really understand what you mean by other questions you had, but I think that this should help you out a little.

The CSS in the PHP thing should be used to over-ride the css written in the actual stylesheet... unless you want to use this way as the main way. Your choice.

Hope that this helped you out a bit :)
  • SB
  • Moderator
  • Genius
  • User avatar
  • Posts: 8742
  • Loc: Aberdeen, Scotland

Post 3+ Months Ago

The sooner i get this site out of the way the better. I really don't understand what you have just typed Bogey, so trying to work that into the code i currently have is proving to be a bit more irritating than i would like...which is not your fault.

I am very tempted to create a topic in the marketplace forum advertising this site as a job. It may be simple to everyone else but it's just way beyond me and the lack of time i have to actually complete it is also proving to be a pain in the ass.

Thanks for your help Spoof & Bogey.

Post Information

  • Total Posts in this topic: 17 posts
  • Users browsing this forum: No registered users and 92 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.