Different backgrounds for main menu items
Different backgrounds for main menu items
Hello all,
I searched the forum, but could not find my solution.
How can I set a background (in the CSS file) to a specific section of the website ( page with childeren) without making a new template with css files?
So not with a tag in the template!
Example:
Page 1 - background1.gif
- Subpage - background1.gif
- Subpage 2 - background1.gif
Page 2 - background2.gif
Page 3 - background3.gif
Page 4 - background3.gif
Page 5 - background3.gif
Thanks in advance,
Hadion
I searched the forum, but could not find my solution.
How can I set a background (in the CSS file) to a specific section of the website ( page with childeren) without making a new template with css files?
So not with a tag in the template!
Example:
Page 1 - background1.gif
- Subpage - background1.gif
- Subpage 2 - background1.gif
Page 2 - background2.gif
Page 3 - background3.gif
Page 4 - background3.gif
Page 5 - background3.gif
Thanks in advance,
Hadion
Re: Different backgrounds for main menu items
Hi,
go to extensions --> user defined tags. There add a new tag with name page_class. Insert this code:
Save the new tag. Go to your template and make this:
Thats all. Now every page will have a personal body class.
neophron
go to extensions --> user defined tags. There add a new tag with name page_class. Insert this code:
Code: Select all
global $gCms;
$classes = array();
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
$currentContent =& $currentNode->getContent();
array_unshift($classes, $currentContent->Alias());
$currentNode =& $currentNode->getParentNode();
}
echo implode($classes, ' ') . ' ' . implode($classes, '-') . ' ' . 'page-' . $thisPage;
Thats all. Now every page will have a personal body class.
neophron
Re: Different backgrounds for main menu items
hey,
i think it's even easier if you just do this, in the Template:
now, every body id is equal to the pagealias plus "Page"--so, home is, "homePage
EDIT: I TYPOED.
it's $page_alias, NOT $pagealias!! You need the underline.
i think it's even easier if you just do this, in the Template:
now, every body id is equal to the pagealias plus "Page"--so, home is, "homePage
EDIT: I TYPOED.
it's $page_alias, NOT $pagealias!! You need the underline.
Last edited by streever on Sat Nov 17, 2007 2:19 pm, edited 1 time in total.
Re: Different backgrounds for main menu items
thanks all
applaud

Re: Different backgrounds for main menu items
Yeah, but he wanted a class indicating just the TOP LEVEL categories. So you have to change the last line toneophron wrote:Save the new tag. Go to your template and make this:Code: Select all
global $gCms; $classes = array(); $manager =& $gCms->GetHierarchyManager(); $thisPage = $gCms->variables['content_id']; $currentNode = &$manager->sureGetNodeById($thisPage); while( isset($currentNode) && $currentNode->getLevel() >= 0 ) { $currentContent =& $currentNode->getContent(); array_unshift($classes, $currentContent->Alias()); $currentNode =& $currentNode->getParentNode(); } echo implode($classes, ' ') . ' ' . implode($classes, '-') . ' ' . 'page-' . $thisPage;
Thats all. Now every page will have a personal body class.
neophron
Code: Select all
echo $classes[0];
Alex
Re: Different backgrounds for main menu items
Hi,
just fooled around a bit with this ... found a nice solution.
The UDT (I called it "bgimage") now checks if a file with the corresponding name really exists, if not it just uses a default pic.
The UDT:
Now, in your page template in the HEADER DIV you use
Voila ... now you have a default pic to start with (or just leave it for certain sections), and all you have to do to activate a section-specific background is to upload a file with the same name as the top level page-alias.
Have fun,
Alex
just fooled around a bit with this ... found a nice solution.
The UDT (I called it "bgimage") now checks if a file with the corresponding name really exists, if not it just uses a default pic.
The UDT:
Code: Select all
global $gCms;
$classes = array();
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
$currentContent =& $currentNode->getContent();
array_unshift($classes, $currentContent->Alias());
$currentNode =& $currentNode->getParentNode();
}
$picname =$classes[0];
$filename = '/server/path/to/your/uploads/images/backgrounds/'.$picname.'.jpg';
if (file_exists($filename)) {
echo '/uploads/images/backgrounds/'.$picname.'.jpg';
} else {
echo '/uploads/images/backgrounds/standard.jpg';
}
Code: Select all
<h1><a style="background-image: url({bgimage};" href="/">Your Title goes here</a></h1>
Have fun,
Alex
Last edited by faglork on Fri Nov 23, 2007 12:55 pm, edited 1 time in total.
- lollipop27
- Forum Members
- Posts: 237
- Joined: Wed Sep 12, 2007 4:09 pm
Re: Different backgrounds for main menu items
Hi,
I love this tag, because I didn't know you can check if files exist...
Is there a possibility to check if the 4th level node page-alias exists and then insert that one, otherwise check if the third level node page-alias exists, then take this one or if non of this works take a default picture?
Thanks a lot....
I love this tag, because I didn't know you can check if files exist...
Is there a possibility to check if the 4th level node page-alias exists and then insert that one, otherwise check if the third level node page-alias exists, then take this one or if non of this works take a default picture?
Thanks a lot....
Re: Different backgrounds for main menu items
Yes. The whole list is in the "classes" array ... just find out the length of the array, and then check forlollipop27 wrote: Is there a possibility to check if the 4th level node page-alias exists and then insert that one, otherwise check if the third level node page-alias exists, then take this one or if non of this works take a default picture?
classes[xx] down to classes[0] ...
You could even skip that array altogether. You could check for the file right there in the while loop which generates the array.
But it is okay with the array ... gives you more possibilities.
hth,
Alex
Last edited by faglork on Fri Nov 23, 2007 12:51 pm, edited 1 time in total.
- lollipop27
- Forum Members
- Posts: 237
- Joined: Wed Sep 12, 2007 4:09 pm
Re: Different backgrounds for main menu items
thanks... great!!!
It works....
Larissa
It works....
Larissa
Re: Different backgrounds for main menu items
oops
I actually wrote a plugin called "sectiontitle" that can give you an up level title.
check it in dev.cmsmadesimple.org
I actually wrote a plugin called "sectiontitle" that can give you an up level title.
check it in dev.cmsmadesimple.org
Re: Different backgrounds for main menu items
Hi,
I tried this out and it finds the default image but it doesn't find an image with the same name as an alias.
if the alias is 'aboutus' then do I simply call the image 'aboutus.jpg'?
I tried this out and it finds the default image but it doesn't find an image with the same name as an alias.
if the alias is 'aboutus' then do I simply call the image 'aboutus.jpg'?
Re: Different backgrounds for main menu items
Double-check the SERVER PATH:declanreynolds wrote: Hi,
I tried this out and it finds the default image but it doesn't find an image with the same name as an alias.
Code: Select all
$filename = '/server/path/to/your/uploads/images/backgrounds/'.$picname.'.jpg';
/www/110/home/html/uploads/images/backgrounds/
NOT /uploads/images/backgrounds/
NOT www.yyyy.com//uploads/images/backgrounds/
Look in your config.php - you find the server path to your root directory in
$config['root_path']=/www/zzzz/vvv
so your server path to the backgrounds directory as given in the example would be
/www/zzzz/vvv/uploads/images/backgrounds
Yes. All lower case.declanreynolds wrote:
if the alias is 'aboutus' then do I simply call the image 'aboutus.jpg'?
hth,
Alex
Re: Different backgrounds for main menu items
I'm pretty sure the path is correct as it finds the default image. It doesn't find the images that are named the same as the top levels.
This is my path:
$picname =$classes[0];
$filename = '/uploads/images/banners/'.$picname.'.jpg';
if (file_exists($filename)) {
echo '/uploads/images/banners/'.$picname.'.jpg';
} else {
echo '/uploads/images/banners/banner_girls.jpg';
}
You can see here: http://mrc.iformat.com.au/ that there is a picture of some girls and this is banner_girls.jpg
If you click 'Settlement Services' this goes to http://mrc.iformat.com.au/index.php?pag ... t-services
Its alias is services-and-information-2
I have an image called services-and-information-2.jpg but it doesn't find it.
I'm sure I'm doing something wrong but I don't know what.
Thanks for your time.
This is my path:
$picname =$classes[0];
$filename = '/uploads/images/banners/'.$picname.'.jpg';
if (file_exists($filename)) {
echo '/uploads/images/banners/'.$picname.'.jpg';
} else {
echo '/uploads/images/banners/banner_girls.jpg';
}
You can see here: http://mrc.iformat.com.au/ that there is a picture of some girls and this is banner_girls.jpg
If you click 'Settlement Services' this goes to http://mrc.iformat.com.au/index.php?pag ... t-services
Its alias is services-and-information-2
I have an image called services-and-information-2.jpg but it doesn't find it.
I'm sure I'm doing something wrong but I don't know what.
Thanks for your time.
Re: Different backgrounds for main menu items
PLEASE re-read my post. This is NOT a server path. It will only work with a "server path". What you specified is a path relative to document root. This is NOT what you need.declanreynolds wrote: I'm pretty sure the path is correct as it finds the default image. It doesn't find the images that are named the same as the top levels.
This is my path:
$picname =$classes[0];
$filename = '/uploads/images/banners/'.$picname.'.jpg';
Cheers,
Alex
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Different backgrounds for main menu items
BTW, the CustomContent module (version 1.4.10) has these abilities built in..... so if you're using it anyways, you could do stuff like:
[edit]
If you put the above code in the head part of your page template, you could simply do a:
in the body of your page template.... and set the background image, or background color any way you wanted for each root page.
Code: Select all
{capture assign='root_alias'}{$ccuser->get_root_alias()}{/capture}
{capture assign='root_title'}{$ccuser->get_page_title($root_alias)}{/capture}
{capture assign='parent_alias'}{$ccuser->get_parent_alias()}{/capture}
{capture assign='parent_title'}{$ccuser->get_page_title($parent_alias)}{/capture}
If you put the above code in the head part of your page template, you could simply do a:
Code: Select all
</__body id="{$root_alias}">
<!-- the rest of my content -->
<__body>
Last edited by calguy1000 on Sun Dec 09, 2007 10:51 pm, edited 1 time in total.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.