Jump to content

Recommended Posts

Can somebody help me out with this?

I am using Egesto as my theme, and automatically it came with a script that would highlight the current page in the top menu.

i think the code is one of these lines..

 

'<?php if ( has_nav_menu( 'main-menu' ) ) { ?>

<?php wp_nav_menu( array( 'theme_location' => 'main-menu', 'menu_class' => 'mainnav superfish' ) ); ?> '

 

Anyways, I wanted to make a customized drop down menu. So I removed that top line of code, and put in a line of code to refer to a plugin I downloaded. In the plugin is the HTML for the customized drop down menu...however, the current page is no longer highlighted in the menu..

 

I tried looking this up, seeing something about CSS and giving each link an id, and putting the id in the body tag of each page...HOWEVER, i can not find a body tag for each of my pages, as it is only in the HEADER of the overall website..

 

Can anyone help me with this?

 

THANK YOU!

Link to comment
https://forums.phpfreaks.com/topic/236102-highlighting-current-page-in-menu/
Share on other sites

well seeing just some php (in a html forum) wont help use. Anyway the most used technique for indicating where you are in a menu is by giving it a class.

 

so often you will see that suddenly an item has a class of "active". See for instance the buttons of phpfreaks.com.  If your in the forum the following is the markup for it:

 

<a class="active firstlevel" href="http://www.phpfreaks.com/forums/index.php">
<span class="firstlevel">Forum</span>
</a>

 

as you can see it has both a class of active and first level. As far as sucker fish son of sucker fish, there are loads of tutorials on that. Anyway i hope you got the idea on how to indicate that a menu item is active. (by assigning a class)

 

If you have no idea what i mean, get firebug for firefox, right click and inspect element.

 

-> edit you might want to scroll down abit on this page: http://hostmonsterforum.com/showthread.php?5803-php-and-class-quot-active-quot-for-menu

 

Seems someone wrote a nice function to do this.

there are only 2 code snippets on that forum? And if your not following it, calling it junk is a bit odd.

Anyway the folowing could be some thing to have a look at and adjust it to your needs

$pages["home"] = "home page";
$pages["products"] = "our products";
$pages["contact"] = "contact us";

$active_page = $_GET["page"];

foreach($pages as $page => $page_title)
{
  $suffix = ($page == $active_page) ? "_active" : "";
  $nav.= "<a href='?page=".$page."' class='navigation".$suffix."'>$page_title</a>";
}

print $nav;  

.

 

Anyway the general idea is that you give a class to the menu button of for instance "active" tha n in css you just style that class.

in php you can write a function to see what what page you are one, like the code above that assumes you have a $_GET variable

http://yourdomain.com/index.php?page=home

 

Hope this helps a bit.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.