By greygoo on
How do I hide the text for the primary links and just use images instead for Drupal 5? All the solutions I've found so far are geared for Drupal 4 or doesn't work for me. I've figured out how to use css background images but it still shows the text part of the primary links menu.
Comments
Any help/advice/suggestion
Any help/advice/suggestion would be appreciated.
Maybe NiceMenus
I tried for a while but everytime I hide the text the bg image goes away too
I have used NiceMenus to display the secondary links with a good amount of control over the appearance
Maybe that would give you the control you need...
http://drupal.org/project/nice_menus
and look here
http://drupal.org/project/nice_primary_menus
for primary-links specific
~are you netsperienced? http://netsperience.org
~are you netsperienced?
♥ follow me @decibelplaces ∞
From All the available
From All the available methods I choose the 'fixed-height', 'padding-top', 'overflow-hidden' trick, or "Dwyer Method" apparently.
To make it work in Drupal, I usually modify the template a little to add a useful ID to the LI element, then pick up on the Anchor in my CSS. to attach the background to.
I modify this a bit if I'm using image generation techniques on-the-fly however.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
editing the theme page.tpl.php to make primary links images
First, create the primary links you want with some text (you will remove the text later)
Display the page in a browser and leave it there
Then open up your theme page.tpl.php file in an editor and comment out the primary links constructor
Then open the source of the page with the primary links in the browser and look for something like:
copy it and paste into page.tpl.php directly below or above the commented out code
now remove the text you created and add the images you want (I would suggest moving the link text to the alt attribute for the image):
you may need to edit your theme css stylesheet further to remove any bg images (eg in Garland theme) or other unwanted styles
~are you netsperienced? http://netsperience.org
~are you netsperienced?
♥ follow me @decibelplaces ∞
Party like it's 1999
If you want to use that approach, go all the way ad :
- View-source on that page
- save-as and name that html as page-pagename.tpl.php
- Now you can manually edit all the HTML as you want!
:-/
My point is that you should instead see how the CONTENT MANAGEMENT SYSTEM builds those menu links, then slightly adapt that. Not throw it away and replace it with a static paste.
All this actually takes is a few lines in your template.php - overrides for maybe theme_menu_item() - a one line function, theme_menu_item_link() - one more line of code. theme_menu_links if the question is actually about 'Primary links 'and not normal menus.
It's very Web 1.0 to replace semantic text links with image buttons. It's just not done any more (unless you are using Adobe goLive or something).
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Don't do it!
dman's quite right, don't manually insert links and certainly don't replace text with images in that manner! Not only are you making more work for yourself in the long run, but also you're making your links less accessible.
Have a look at this post: http://www.nicklewis.org/node/843
Hopefully that will answer most of your questions.
without tampering with core code
There are many ways to add the images - the main problem here is removing the text (or omitting it) while still displaying the bg image as the primary link
Doesn't matter if you would not use an image for a link, that was the original question here
any css like display:none or content:"" will nullify the primary link and not display the bg image either - that is why I moved the images to the links
the first comment at http://www.nicklewis.org/node/843 is "nice but how do I remove the text?"
it seems one would have to change core code to add a
<span>or other container around the text and mods would be lost when upgrading the core codemy solution, while static and not exactly elegant, only requires a couple of edits to the theme template
~are you netsperienced? http://netsperience.org
~are you netsperienced?
♥ follow me @decibelplaces ∞
Image replacement
There are many ways of doing this in CSS, each with their pros and cons.
Google turned this up for image replacement techniques:
http://css-tricks.com/nine-techniques-for-css-image-replacement/
If you chose a technique that used an extra span, you could easily add one in the theme layer, no need to tamper with core.
Might be http://api.drupal.org/api/function/theme_links/5 (sorry, can't remember right now).
My first post above
My first post above http://drupal.org/node/268732#comment-900496 Presented proper image replacements, certainly not display:none !
And if you really thought you needed or wanted to add a span or class to this or any part of Drupal rendering - then that is what I discussed above to just theme the code around just the menu_link_item. Please look into the theme guide to learn how theme_hooks() work. it's incredibly powerful and selective, and exactly the opposite of touching core code!
Not only is it best practice, it's easier even than copy & paste!
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
what am I missing here?
There are no lack of methods to place images as background on Primary Link elements. noborders said
That is not why I chose to make them a regular images in the links.
The problem is removing the Primary Links text without nullifying the entire link.
You cannot create a Primary Link with null or a space " "
The methods I tried to hide the link including display:none and content:"" got rid of the text and the entire link - the bgimage did not display either, throwing out the baby with the bathwater.
I think the Dwyer method (see below)
would have the same effect without a
<span>or other container specific to the Primary Link text.dman,
The Dwyer method most certainly relies on a
</span>tag surrounding the text:McJim,
Where in this function is the link text isolated so we may add a class or id to it alone, not the entire link?
And are you suggesting integrating this modified function into the theme template?
(from http://api.drupal.org/api/function/theme_links/5 )
When all is said and done, for my money I would prefer changing a couple of lines of code in my template.
~are you netsperienced? http://netsperience.org
~are you netsperienced?
♥ follow me @decibelplaces ∞
Example
Here's a Drupal site with image replacement for the primary links: http://chem.uk.com/
Have a look at the CSS.
Container Handling ... web site css
Ok they have an id "#general-navigation" not sure if that is theme specific
without the id this would affect every ul list
would it work to sub "ul.primary-links" for "#general-navigation"?
I guess you could do it this way, including the change on hover
~are you netsperienced? http://netsperience.org
~are you netsperienced?
♥ follow me @decibelplaces ∞
The Dwyer method most
Or an
<a href="link">text</a>tag. :-)I'm not sure of the name then, if it even has one then if that summary says it 'requires' a span. I've not needed it :-}
... but as noted, there's plenty of alternatives.
I choose not to use the hokey 'primary links' rendering much, and usually use full menu rendering, meaning that the theme function to override is :
... plus I can copy it between my other themes when needed.
Generally I stick a munged version of the title into the link attributes.
... But this is all because I make sites that move around a bit, sometimes have the menu change, or the items get renamed, sometimes get upgraded to use different or new versions of the theme.
If none of this is an issue, then do whatever works. I just tend to go for the maintainable general case, which sometimes looks like the long way around.
But theming the menus is such a powerful example, I often start with that one when teaching how easy Drupal themes are.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
I think this is it
using
the text is gone but the Garland theme bg images are still there
so to replace the bg images - for each menu item (example here is in Garland theme)
(make sure it is placed after the css that sets the theme bg images, if any)
This is a css solution I can live with, thanks all for the suggestions
~are you netsperienced? http://netsperience.org
~are you netsperienced?
♥ follow me @decibelplaces ∞
Would this also work for
Would this also work for Primary Links block?
Primary Links blocks with images
sure, but I would recommend using Nice Menus for more precise CSS selectors.
This site uses two different Nice Menus as a horizontal menu (on the homepage) and as a left sidebar menu:
http://intel.anteriorstudios.com/
They are text links with background images.
Here are some of the styles for the menus:
~are you netsperienced? /\_][_][_/\ Reliable Web Hosting - cheap!
~are you netsperienced?
♥ follow me @decibelplaces ∞
Hi. But I meant how do I
Hi. But I meant how do I only use images and not text for the primary links block? I know how to use background images with css but the main thing I've been trying to figure in this whole thread is how to have the text not show at all on each menu.
already answered
did you try the methods previous in the thread?
I think this is it
decibel.places - June 29, 2008 - 15:44
~are you netsperienced? /\_][_][_/\ Reliable Web Hosting - cheap!
~are you netsperienced?
♥ follow me @decibelplaces ∞
Yes, I tried it but didn't
Yes, I tried it but didn't work for me. Is it Garland specific? I'm using bluemarine.
check your menu elements with Firefox/Firebug
The example was with Garland but the method should work in other themes.
I recommend using Firefox with the Firebug addon to inspect the menu elements, and if you wish you can use the Web Developer addon with Edit CSS to see your changes before you save and upload.
~are you netsperienced? /\_][_][_/\ Reliable Web Hosting - cheap!
~are you netsperienced?
♥ follow me @decibelplaces ∞
imagemenu module
http://drupal.org/project/imagemenu
~are you netsperienced? /\_][_][_/\ Reliable Web Hosting - cheap!
~are you netsperienced?
♥ follow me @decibelplaces ∞
Text Indent
Simply add the following code to your CSS file:
(the 220 will be different depending on which primary link you are dealing with.)