Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post

    php &thispage= and css menu

    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

    PHP Code:
    <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?

    PHP Code:
    <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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    The blog scripts use a different CSS file?
    So the "selected" class doesn't exist in the other CSS file.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    How are you populating the $currentPage variable?
    If you print that out, does it show 'blogpage1' for its value?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by mlseim View Post
    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

  • #5
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Fou-Lu View Post
    How are you populating the $currentPage variable?
    If you print that out, does it show 'blogpage1' for its value?
    Every page has

    PHP Code:
    $currentPage="pagename"
    I just tried adding

    PHP Code:
    <?php echo "$currentPage"?>
    And it doesn't show anything when browsing blog

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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).

  • #7
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    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?

  • #8
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Can anyone help? Don't mean to sound pushy, just in a rush ha

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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 Code:
    <?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?

  • #10
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    There isnt a great deal to the menu

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

    PHP Code:
    <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

  • #11
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Unfortunately that didn't work

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Are you actually setting:

    Code:
    $currentPage = 'blog';
    in your *blog* scripts?

  • #13
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by MattF View Post
    Are you actually setting:

    Code:
    $currentPage = 'blog';
    in your *blog* scripts?
    I was yes, tried in header, index and single.php to no avail

  • #14
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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>

  • #15
    New Coder
    Join Date
    Jan 2006
    Posts
    88
    Thanks
    4
    Thanked 1 Time in 1 Post
    Hi mlseim,

    It Shows "Blog -includes"

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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •