...

View Full Version : php &thispage= and css menu



reyna12
11-02-2010, 10:26 PM
Hi,

I have a main site & a blog (/blog) which both use the same menu (/includes/right.php).

In the menu (right.php) i have a css menu, which when the page is active the menu shows in an active state


<li class="home"><a href="http://www.active-driving.co.uk/index.php" <?php if($currentPage=="index") { echo "class='selected'"; }?> title="Back to our Home Page"><span class="displace">Home</span></a></li>

But it doesn't work for the blog, is this because the blog is in a different directory?


<li class="blog"><a href="http://www.active-driving.co.uk/blog" <?php if($currentPage=="blogpage1") { echo "class='selected'"; }?> title="Read our Blog"><span class="displace">Blog</span></a></li>

Any help is appreciated :)

Thanks

mlseim
11-02-2010, 11:39 PM
The blog scripts use a different CSS file?
So the "selected" class doesn't exist in the other CSS file.

Fou-Lu
11-02-2010, 11:40 PM
How are you populating the $currentPage variable?
If you print that out, does it show 'blogpage1' for its value?

reyna12
11-02-2010, 11:51 PM
The blog scripts use a different CSS file?
So the "selected" class doesn't exist in the other CSS file.

The menu has css rollovers that work fine, the "right.php" is using the same css file as the main site, the rollovers and active state work perfect for every other page. I tried adding the css to the blogs css, no change

reyna12
11-02-2010, 11:57 PM
How are you populating the $currentPage variable?
If you print that out, does it show 'blogpage1' for its value?

Every page has


$currentPage="pagename";

I just tried adding


<?php echo "$currentPage"; ?>

And it doesn't show anything when browsing blog

Keleth
11-03-2010, 12:18 AM
Then that means $currentPage is being emptied or isn't being set somewhere. (By the way, when just echoing a variable, it doesn't need quotes).

reyna12
11-03-2010, 12:23 AM
its wordpress im using, http://www.active-driving.co.uk/

as you can see, variable is echoed above menu for now.

could i make it so if url contains 'blog', then echo "class='selected' as a workaround?

reyna12
11-03-2010, 04:54 PM
Can anyone help? Don't mean to sound pushy, just in a rush ha :)

mlseim
11-03-2010, 06:17 PM
Show us the script you use to generate the menu on the left side.
(I think you call it "right.php" ?)

I'm thinking that you have to treat the BLOG link a bit different,
since it's a script in a different directory, like you mentioned earlier.

I want to see what the whole "right.php" script looks like.

=================

I'm thinking that you'll have to look for the directory called "blog".



<?php
$currentFolder = basename(dirname(__FILE__));
?>
<li class="blog"><a href="http://www.active-driving.co.uk/blog" <?php if($currentFolder=="blog") { echo "class='selected'"; }?> title="Read our Blog"><span class="displace">Blog</span></a></li>


Sort of like that?

reyna12
11-03-2010, 06:36 PM
There isnt a great deal to the menu

Each menu item is like the below, that's all that's really in it.


<li class="blog"><a href="http://www.active-driving.co.uk/blog" <?php if($currentPage=="blog1") { echo "class='selected'"; }?> title="Read our Blog"><span class="displace">Blog</span></a></li>

with each page having the

&currentPage defined in it.

I'll try your solution now and report back

reyna12
11-03-2010, 06:38 PM
Unfortunately that didn't work :(

MattF
11-03-2010, 07:07 PM
Are you actually setting:



$currentPage = 'blog';


in your *blog* scripts?

reyna12
11-03-2010, 07:59 PM
Are you actually setting:



$currentPage = 'blog';


in your *blog* scripts?

I was yes, tried in header, index and single.php to no avail :(

mlseim
11-04-2010, 12:34 AM
Try this and see what it shows for the variable ...
It will put the variable value on the line.
Blog - something
Just a test to see what it says.
Let me know.


<?php
$currentFolder = basename(dirname(__FILE__));
?>
<li class="blog"><a href="http://www.active-driving.co.uk/blog" <?php if($currentFolder=="blog") { echo "class='selected'"; }?> title="Read our Blog"><span class="displace">Blog -<?=$currentFolder?></span></a></li>

reyna12
11-04-2010, 11:33 AM
Hi mlseim,

It Shows "Blog -includes"

Which is the directory the right.php is located rather than the blog

mlseim
11-04-2010, 12:33 PM
Reyna ...

doh!

... you can see where I'm heading with this ... but not quite there.

This will give us the URL:
$url = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

In this case, $url will be: "index.php"

We want to see if we are at: "/blog/index.php"

So maybe that route might work ... but my example needs to be tweaked.

reyna12
11-04-2010, 01:44 PM
Sorry i have to say i'm pretty unsure as to where to go / what to do with that? I'm not particularly fluent in php

mlseim
11-04-2010, 03:01 PM
Try this and tell me what it says ...

It will say: Blog - something



<?php
$test = $_SERVER["SCRIPT_NAME"];
?>
<li class="blog"><a href="http://www.active-driving.co.uk/blog" <?php if($currentFolder=="blog") { echo "class='selected'"; }?> title="Read our Blog"><span class="displace">Blog -<?=$test?></span></a></li>

reyna12
11-04-2010, 04:14 PM
Try this and tell me what it says ...

It will say: Blog - something



<?php
$test = $_SERVER["SCRIPT_NAME"];
?>
<li class="blog"><a href="http://www.active-driving.co.uk/blog" <?php if($currentFolder=="blog") { echo "class='selected'"; }?> title="Read our Blog"><span class="displace">Blog -<?=$test?></span></a></li>


Hi, it comes out with this:


Blog -/includes/right.php

mlseim
11-04-2010, 04:29 PM
In your blog (your WordPress script),
how are you including that menu "right.php"?

Do you specify that in a template somewhere?

reyna12
11-04-2010, 04:59 PM
It's in the blogs header.php


<div id="content">
<?php include("http://www.active-driving.co.uk/includes/right.php"); ?>
<div id="maincontent">

mlseim
11-04-2010, 05:24 PM
OK,

So this idea is really lame ... but I can't think of anything else.

Take your "right.php" script and make another copy of it as "right2.php".
Force the line with BLOG to be "selected"

<li class="blog"><a href="http://www.active-driving.co.uk/blog" class="selected"> title="Read our Blog"><span class="displace">Blog</span></a></li>

Then change the include so it picks "right2.php" instead of "right.php"




.

MattF
11-04-2010, 05:32 PM
I was yes, tried in header, index and single.php to no avail :(


It's in the blogs header.php


<div id="content">
<?php include("http://www.active-driving.co.uk/includes/right.php"); ?>
<div id="maincontent">

You are setting the $currentPage var *before* that include in the blog header script, i.e:



<?php

$currentPage = 'blog';

[ ... rest of code here ...]
?>
<div id="content">
<?php include("http://www.active-driving.co.uk/includes/right.php"); ?>
<div id="maincontent">

Same as mlseim, (unless something else is setting that var in the include script itself), I can't see any reason why it shouldn't be working fine as is.

reyna12
11-04-2010, 06:04 PM
I've implemented a simple fix, not quite sure why i hadn't thought of it. Perhaps not the best fix but it works.

Since it's not actually setting the $currentPage...


<?php if($currentPage=="") { echo "class='selected'"; }?>

MattF
11-04-2010, 06:09 PM
Just out of curiosity, (this is assuming the include dir is one level above the blog dir?), could you try changing that include to this and seeing if anything changes with regards to that page var being available:



<?php include("../includes/right.php"); ?>

reyna12
11-04-2010, 06:27 PM
Just out of curiosity, (this is assuming the include dir is one level above the blog dir?), could you try changing that include to this and seeing if anything changes with regards to that page var being available:



<?php include("../includes/right.php"); ?>


Hi Matt, That actually works as well! Thanks for that, howcome having the full url causes problems?

mlseim
11-04-2010, 06:37 PM
Matt ...
I thought of that too, but said to myself, "nah, that shouldn't make a difference."
Woe is me! I learned something new today, thanks.

MattF
11-04-2010, 06:44 PM
howcome having the full url causes problems?

I've absolutely no idea. :D As mlseim mentioned above, there's not really any known reason, (that I've ever noted), why it should. It's called clutching at straws just to test. :D Good one to know for future reference though. Cheers for testing that theory. :)

MattF
11-04-2010, 06:47 PM
Matt ...
I thought of that too, but said to myself, "nah, that shouldn't make a difference."

I didn't think it would make any difference either, but to use the old Sherlock Holmes type analogy, whatever is left, however improbable... :D It was worth checking for future reference if nowt else. :D

reyna12
11-04-2010, 07:01 PM
cheers 4 all ure help :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum