amuck-landowner

quick PHP question

shovenose

New Member
Verified Provider
I use the following code at the top of each page...


<?php
$pageTitle = 'Reseller Hosting';
include 'header.php';
?>

Then in header.php


<!-- Menu-->
<ul id="menu" class="sf-menu">
<li <?php if ($pageTitle=="Home") echo 'class="current"'; ?>><a href="index.php">Home</a></li>
<li <?php if ($pageTitle=="Web Hosting") echo 'class="current"'; ?>>
<a href="#">Hosting</a>
<ul>
<li><a href="webhosting.php">Web Hosting</a></li>
<li><a href="resellerhosting.php">Reseller Hosting</a></li>
<li><a href="email.php">Email Hosting</a></li>
</ul>
</li>
<li <?php if ($pageTitle=="Virtual Private Servers") echo 'class="current"'; ?>>
<a href="#">Servers</a>
<ul>
<li><a href="vps.php">Virtual Private Servers</a></li>
<li><a href="dedicatedservers.php">Dedicated Servers</a></li>
</ul>
</li>
<li <?php if ($pageTitle=="Domain Names") echo 'class="current"'; ?>><a href="domains.php">Domain Names</a></li>
<li <?php if ($pageTitle=="SSL Certificates") echo 'class="current"'; ?>><a href="ssl.php">SSL Certificates</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
<!-- End Menu-->

Now, how would I make it so that the Hosting category is highlighted if they're on Web Hosting, Reseller Hosting, and Email Hosting, and Servers category is highlighting if they're on either Virtual Private Servers or Dedicated servers?

Thanks.
 

Mun

Never Forget
Welcome to VPSboard help, 

We are currently spawning many people to help you give. us one sec.....
 

Mun

Never Forget
so you want "<a href="#">Hosting</a>" to be highlighted so people see it from the start?
 

MCH-Phil

New Member
Verified Provider
The PHP needed is there, now you just need the CSS for .current.

Or are you saying the PHP isn't placing the .current on the tags?
 

netnub

New Member
OR, theres a neat thing called JQUERY. If URL contains "vps" THEN add class to LI tag. Google it.

First method:

var page = "vpsPage";
$(function() {
if ( page.indexOf('vps') > -1 ) {
    alert('VPS');
    $('#ul-tags').append('<li class="active"><a href="vps.html">VPS</a></li>');
}
});



Second method:

Code:
$(function() {
if ( document.location.href.indexOf('vps') > -1 ) {
    // Run JS code here, ex:
   $(".li-vps").html("This just got replaced due to VPS in URL.");
}
});
 
Last edited by a moderator:

shovenose

New Member
Verified Provider
No you all have it wrong. the code works perfectly fine! But the problem is that I have drop downs, I just need to figure out how to make the parent li current if they open a child.
 

MCH-Phil

New Member
Verified Provider
<?php if ($pageTitle=="Web Hosting" || $pageTitle=="Reseller Hosting" || $pageTitle=="Email Hosting") echo 'class="current"'; ?>
I think this is what you want.
 
Last edited by a moderator:

Aldryic C'boas

The Pony
No offense OP, but you really need to work on your consistency.  Jumping back and forth between string formats, for example, will just create a headache for whoever's auditing your code.
 

MCH-Phil

New Member
Verified Provider
The advice to change up " to ' is solid.  No problem though :D
 
Last edited by a moderator:

Mun

Never Forget
More like so we understand what you want @shovenose so we don't have to guess.

Provide more info instead of less.
 
Top
amuck-landowner