I want to use images to replace my text primary links.
I used the following solution: http://drupal.org/node/110199#comment-2561676
The above solution says to cut and paste the following code into template.php file:
function template_preprocess_page($variables) {
$primary_links = theme_get_setting('toggle_primary_links') ? menu_primary_links() : array();
foreach ($primary_links as $key => $link) {
$primary_links[$key]['html'] = TRUE;
$primary_links[$key]['title'] = '<span></span>' . $primary_links[$key]['title'];
}
$variables['primary_links'] = $primary_links;
}
However, when I cut and paste the above code into template.php file, i get the following error:
Fatal error: Cannot redeclare template_preprocess_page() (previously declared in /Users/myname/Sites/drupal/includes/theme.inc:1807) in /Users/myname/Sites/drupal/sites/all/themes/mysite/template.php on line 18
Does this mean that i need to put the code in theme.inc file instead? And where in theme.inc?
Another problem with the above solution (http://drupal.org/node/110199#comment-2561676) is the following CSS:
#header .primary-links li.menu-XXX a span {
position: absolute;
width: 200px;
height: 40px;
background: url('../images/menu-item.gif') top left no-repeat;
}
So XXX is the menu ID, as in the name of that particular menu: home, about, contact, blog. I tried that but it doesnt work.
Please help.
Comments
anyone, please?
anyone, please?
The problem is that you cut
The problem is that you cut and pasted your code into the (probably bottom) of the file, but that file already has a function
template_preprocess_page
on line 18.Remove your cut and paste, then take the actual code:
and put it inside the existting
template_preprocess_page
function.The menu-XXX actually refers to the menu item number, not the name.
you said and put the php code
you said and put the php code inside the existting template_preprocess_page function.
Where is this function? Is it in the theme.inc file?
Where is this function? Is it
No, theme.inc is part of Drupal core. It's in the same place as you put your cut & paste code: template.php - line 18 in your case.
No, the menu item number is shown as a CSS class - but it just occurred to me that on this site there is no such information. However this does happen in Garland, because in page.tpl.php it uses the theme_links function.
Since you gave a CSS example I simply assumed that the theme you're using does the same.
Example:
So the mlids (menu link identifiers) are 5541 and 5551. If you don't need different images for each menu item, then this information is superfluous...
Okay this is what i have in template.php
So I don't see the preprocess function on line 18?
since I'm not getting much
since I'm not getting much help here, I have posted another request on Post Installation forum regarding the first half of my code only.
I really need to resolve this, and I really want to use a DIFFERENT image for each primary link menu item.
Thanks.
Hi Bookwalla, Yes
Hi Bookwalla,
Yes
template_preprocess_page(&$vars)
is a function which already exists. It's a theme preprocess function. What you can do is extend it with your own implementation.This is what you do:
1. Copy my function to your template.php
2. Rename the function from
template_preprocess_page(&vars)
to<yourthemename>_preprocess_page(&$vars)
Where "yourthemename" is the name of your theme. If you named your theme "bakery", your preprocess function in template.php would be namedbakery_preprocess_page(&$vars)
OR you could also call your functionphptemplate_preprocess_page(&$vars)
which is equally good.What Drupal's theming layer will do during a page call: it will first call
template_preprocess_page(&$vars)
which is an existing function in theme.inc, next it will take a look at your template.php and look for a variation on that function.Knowing how to preprocess functions and templates work/relate to each other really gives you an edge if you want to theme hard stuff: Just read up on the Drupal Theming Guide! :-) http://drupal.org/theme-guide/6
thank you for this in depth
thank you for this in depth reply. this is what i was looking for, but it's sad that a lot of Drupal people don't really help in these forums.
But, yes, you helped me, and i thank you for that :)