By thepaul on
I need to put a inside of the anchor tags of the Primary links.
Example:
<a href="URL"><span>link text</span></a>
How can I do this in Drupal 5 ?
[edit -sepeck: added code tags]
I need to put a inside of the anchor tags of the Primary links.
Example:
<a href="URL"><span>link text</span></a>
How can I do this in Drupal 5 ?
[edit -sepeck: added code tags]
Comments
Ok let me just get you started
I don't have the explanations, but hopefully OTHER people will step in too :)
Adding a
<span></span>to Primary links involve what's called in Drupal terminology "using a themeing function".STEP 1 : Copy & paste : from theme.inc to template.php
Go into includes/theme.inc and find the function theme_links(). Copy that whole code block into
your theme folder file template.php.
STEP 2 : Renaming the function (that you just pasted in STEP 1) and, optionnally, giving it extra or altogether different arguments. In template.php.
The function's name must start with : phptemplate_ (that's a rule)
It must NOT be named phptemplate_links because it would theme all your links. And you only want to affect
primary links.
For example, the name could be :
function phptemplate_primary_links($links, $attributes = array('class' => 'links')) {STEP 3 : In your template file, i.e. page.tpl.php insert the following code where you want to print your primary links :
The first argument to the theme function must be the name you gave your themeing function, after
phptemplate_.The arguments are the ones passed to the phptemplate_primary_links function, as defined (by you) in phptemplate.php.
STEP 4 : Test to see if that did not break anything, that is, check if Primary Links still appear. If it's business as usual.
STEP 5 : Now roll up your sleeves. Time to modify the function in template.php (phptemplate_primary_links) to make it do what you want, i.e. insert a
<span>.There are other ways too !!!
You can have a template file just to print the Primary links.
Caroline
phptemplate seems to be ignoring template.php
Caroline, your explanation was very clear and easy to follow, but after I tried to apply this method to do the exact same thing on my site (i.e. simply add span tags to each of the primary links), my menu simply disappeared.
I've tried a dozen different approaches, and one of two things happens: the menu either disappears entirely from the source code, or the menu formats the same as it always did.
I tried starting very simple, just adding the function override to my template.php file and adding an HTML comment so that I could see that the PHPTemplate engine was reading the template.php override, but no dice. To all appearances, the engine is ignoring my template.php file -- at least, that's my best theory.
I'm incredibly frustrated. I've quadruple-checked spellings, filenames, where I'm uploading to, making sure I have the opening and closing PHP tags:
...Any ideas? Anyone?
Beth
never mind
Ha! Stupid typo -- disregard my post above.
And again, thanks for the earlier info -- once I caught the mistake, everything worked beautifully.
Beth
span inside anchors
This solution http://drupal.org/node/130177#comment-237501 worked for me in Drupal 5.
-------------------------------------------------
AdAstra.ca - Optimze the Web. Optimze the World.
What about Drupal 6
In Drupal 6, if I use:
It works fine to theming all links as Carolina said, but if I rename the function like this:
everything disappear!
(yes, I use "...theme('primary_links',..." as explained in page.tpl )
I think the reason is that in Drupal 6 I have to register the new function in template.php, but I can't understand how this can be done! I need an example please! I read i have to use "hook_theme()" to do so, but... HOW!
Please give me an example.
Thanks
Massimo
same problem here ~_~
same problem here ~_~
Same Problem - Drupal 6
Yup, me too. very frustrating. Can someone shed some light on how to use the theme hooks, including how to register them so they actually get applied in Drupal 6.
Any update on
Any update on this?
Nick
----------------------------------
Nick Young
www.nickbits.co.uk
------------oOo----------------------
Nick Young (www.nickbits.co.uk)
Solution for drupal 6 with zen sub-theme
Here's what you need to do to register the primary_links themable function.
In your template.php, edit hook_theme() to include the new function.
Then just make sure to include the new function.
Don't forget to clear your theme registry.
This is very confusing. I
This is very confusing. I need a WORKING example.
Just cant figure it out... i dont know PHP...
Why the hell was it changed at all... in 4.6 it was all fine.
Working Example for v.5
Make a template.php file in your theme folder.
This code will add a ~ between list items:
<span> in primary links with Zen subtheme
Hi,
I'm creating a subtheme of Zen and need to be able to wrap primary links in a span tags as described in this thread. I noticed that Zen (5.x-1.0) provides the following code in the subtheme's template.php:
What does this code do? I thought it would wrap my primary links in a span tag. I enabled the function override but nothing happened. I have no idea what I'm doing wrong. I've followed the subtheme instructions in the Zen documentation, but changes to the subtheme's template.php have no effect.
I'm new to theming Drupal. Any advice on how to to do this with Zen would be appreciated.
TIA,
Cliftoo
Adding a span tag inside menu links in Drupal 6
This should help http://drupal.org/node/221382
Scroll down to this comment for the final solution http://drupal.org/node/221382#comment-755469. There are issues with the html output which are resolved there.
definitely check out that link
Apparently, I almost had the solution by myself, but the check_plain() stuff was not something I would have figured out on my own. That comment shows a very simple solution and provides a great explanation of how it works.