I'm working on my main tabs and I just noticed that my home page tab does not activate.
On each of the other tabs, theme_links returns the 'active' class when you are on the page represented by the link. This does not seem to apply to the home page.
I made the home page by creating a page type, giving it an index.html path alias (because I could not assign a blank) and then assigning "index.html" as the Default front page in Administer/Site Configuration/Site information.
In Administer/Site Building/Menus I assigned the first menu link to .
Now the menu link works correctly but because "/" does not match up with "index.html", it does not return the "active" class on the menu item.
What is the correct way to assign a home page without any path alias at all? The home page should be "/" or base_url, not "index.html".
Thanks,
Chadj
Comments
correction
Sorry, line should read:
In Administer/Site Building/Menus I assigned the first menu link to <front>.
<front> is causing the lack of active class - maybe?
I had the same problem today. I got round it as follows:
- in Site Information set your default homepage e.g. node/1 using whatever the node number is for the page you want to be the homepage
- ensure none of your pages is promoted to front page
- set your menu "home" link to the address of your homepage e.g. node/1
When I did this the homepage link had the active class, and navigating to www.mydomain.com with no filename specified in the url takes me to the homepage. I assume it is promoting the page to frontpage that causes the active class to not be added but I haven't looked at the code so this is just a guess.
HTH
Thanks
Great suggestion. It worked great for me... 4 years later. lol
Another hack
Looks like this is actually a minor pending bug in Drupal.
I was only able to work around problem with a template hack. Since all other links are working correctly (being assigned the 'active' class when the current page matches the link) I only needed to worry about the home page. So, I added the 'active' class manually on the first menu item when the URI is empty (ie, at the home page). I'm posting the code here in case anyone else has this problem:
Here's an excerpt of my phptemplate_links function in templates.php.
The code section originally read:
I inserted one line to force the extra 'active' class:
thanks, but...
Chadj, thanks for the hack.
However I can't get it working because the template.php (I think you meant 'template.php', not 'templates.php') which came with my theme doesn't contain a phptemplate_links function. I'm only just beginning to understand theme overrides, so if you can post the complete function, that would be a great help.
Marc
Possible workaround
This workaround probably works here too.
If you are using a static front page ( node/23 ) or a view or a panel, or anything but the default 'node' list, you can call the path directly in your menu item, and it will work without any hacks. That is, make your menu a link to what you have set to in site settings, if it's anything but /node
~ben
People Who Give a Damn :: http://pwgd.org/ :: Building the infrastructure of a network for everyone
Agaric Design Collective :: http://AgaricDesign.com/ :: Open Source Web Development
benjamin, Agaric
If you are using a static
If you are using a static front page ( node/23 ) you have two urls for the same content.
I override the theme-functions:
For homepage-link in primary-links I use this function in template.php:
In page.tpl.php for primary- and secondary-links e.g. in zen-theme :
- or in garland and barlow.:
To make a homepage-link active in other menus I use this function in template.php (http://drupal.org/node/87902):
Works for <front> in other menus. Works in garland, barlow, nonzero and zen (in some themes you must change the css - I can poste this too, if desired).
Worked for me
Thanks for posting this overrides phptemplate_menu_links function Petra. This worked great in my zen based setup.
Cheers!
Thanks!
This was a big help. Adding function phptemplate_menu_links and changing print theme worked perfectly.
doesn't work for me
I have tried to make this work with a fresh install of zen and garland (and other themes). I'm not sure what I'm doing wrong... I have followed your instructions exactly and I still cannot produce an "active" state for a primary link item. It is almost as if drupal is not "reading" template.php while loading the page. I have deleted my cache and done all the normal things to make sure that everything is as it should be, but no go.
FYI, I am running Drupal 5.2 on Ubuntu LAMP install. Another thing, after making the changes in garland, the primary links have disappeared completely....
Ok, I've been trying some things out to test and found that when I assign the primary links to "Navigation", the active status works, but when the primary links are assigned to a menu I've built, they don't work...??? Help!
This has been fixed.
Doesn't work on my primary link
Hi Petra,
I am using drupal 5.7.
It works to me but only for the home page, while my other primary link cannot be class-ed 'active'.
To check, I print out $index variable at each loop:
but no 'active' word in each $index, so the primary link cannot be class-ed active.
I have tried to change the function name "phptemplate_menu_links" to "phptemplate_links" (as someone suggested), but still doesn't help.
What else could be the reason?
Thanks in advance.
__
tantotea
Ok.. pheww.. it works now. I
Ok.. pheww.. it works now.
I use Petra's solution.
Previously, in the menu administration page, I set the URL of my primary links to their alias (using URL Alias functionality). It didn't work.
Now, after setting the URL of my primary link to its original URL (in the menu administration page), it works.
It seems like Drupal will auto generate the 'active' class if the URL of a menu item, which is set in the menu administration page, is the original URL (not its alias).
__
tantotea
what about a custom menu?
How do you print out a non standard menu other then the primary and secondary links?
For example: we have a 3rd menu called 'menu_three' and a 4th menu called 'menu_four', what parameters should be alterd in the code
function phptemplate_menu_links($links, $attributes = array())and
<?php print theme('menu_links', $primary_links, array('class' => 'links primary_menu')) ?>Yes, his is working. In my
Possible workaround:
Yes, this is working. In my opinion it has one major drawback in SEO: duplicate URL's for the same content. www.yourdomain.com/ will return the same content as 'www.yourdomain.com/node /#' where node /# matches your homepage. You really want your homepage to be known by searchengines only by the full domainname without trailing someting.
webdesign nijkerk, putten, amersfoort
Note about duplicate content in drupal
You are right about Drupal's creation of duplicate content. However, there are many ways of fixing this from an SEO standpoint.
I just found a post about ways of fixing this here: Changing a page's URL alias breaks existing links. "would be nice" if a module could track and provide 301 redirects.
Here's an excerpt I found particularly helpful.
I use on all of my sites Path Redirect and Global Redirect.
Global Redirect redirects your visitors coming from node/123 to the corresponding alias - with 301.
Path Redirect allows you to specify your old path and its new target.
see this issue
This patch should also solve the problem:
http://drupal.org/node/173459
How did it go?
Were you able to solve the problem?
Gina, Web Designer currently working on the Cancer Treatment Online Pharmacies project.
Confused
Its all so confusing.