PHP/HTML help

Anteeks

macrumors newbie
Original poster
Feb 23, 2012
10
4
Sweden
Code:
So, I'm trying to make a webpage using HTML/CSS and PHP. I divided the project in separate files (one for header, footer, every subpages etc.).

What I want to do is to highlight the current meny choice. I do this by defining a ID per page, and use this ID to access some CSS code.

I define a variable $pageId, that writes out in header.php to get a dynamic ID per page (which I also did with the webpage title).

But the problem is - it doesn't work and I get an annoying "id='me' > " printed out on the left upper screen. The closest I have got to is to hard-code it (which I don't want to) by writing "<body id='pagename' >" which makes the highlightning work, but it still prints out the text on top.

Here is the code for the subpage:

Code:
<?php 
include("incl/config.php");
$pageTitle = "titlename";
$pageId = "me";


$pageStyle = '
figure { 
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
 border-radius: 10px;

 border-color:#5C0A0A;

 -moz-box-shadow: 10px 10px 5px #8A0F0F;
 -webkit-box-shadow: 10px 10px 5px #8A0F0F;
 box-shadow: 10px 10px 5px #8A0F0F;
}
';

?>

<?php include("incl/header.php"); ?>
Code in header.php (where I want to write out the ID).

Code:
<head>

  <title><?php echo $pageTitle; ?></title>
  <?php if(isset($pageStyle)) : ?>
 <style type="text/css">
   <?php echo $pageStyle; ?>
 </style>
 <?php endif; ?> 		

	
</head>
<body><?php if(isset($pageId)) echo " id='$pageId' "; ?>>

<!-- Header -->
<header id="above">
 <nav class="related">
 </nav>
</header>




<header id="top">
 

 <nav class="navmenu">
  <a id="me-"     href="me.php">Me</a>
 </nav>

  </header>
And the code in CSS to highlight the meny choice (when body#id and a#id is equal)

Code:
 body#me a#me-,
{background:#858585;border:2px solid #656565;}
Anyone knows whats wrong with the code?
 

Darth.Titan

macrumors 68030
Oct 31, 2007
2,713
314
Austin, TX
It's right there in your header.php file:
PHP:
</head>
<body><?php if(isset($pageId)) echo " id='$pageId' "; ?>>
should be
PHP:
</head>
<body<?php if(isset($pageId)) echo " id='$pageId' "; ?>>
Note you put a closing > on your body tag before echoing the id. That's why you were seeing "id='me' > " printed out at the top of each page.
 

960design

macrumors 68030
Apr 17, 2012
2,841
841
Destin, FL
I hate it when I do stuff like that.
Three hours on Friday looking for a bug that ended up being =! instead of !=

This silly things we do... my mistakes could have their own web blog