Different backgrounds for main menu items

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
hadion
Forum Members
Forum Members
Posts: 17
Joined: Thu Apr 26, 2007 10:02 am

Different backgrounds for main menu items

Post by hadion »

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
User avatar
neophron
Forum Members
Forum Members
Posts: 145
Joined: Sun Feb 12, 2006 12:11 am

Re: Different backgrounds for main menu items

Post by neophron »

Hi,

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;
Save the new tag. Go to your template and make this:
Thats all. Now every page will have a personal body class.

neophron
streever

Re: Different backgrounds for main menu items

Post by streever »

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.
Last edited by streever on Sat Nov 17, 2007 2:19 pm, edited 1 time in total.
hadion
Forum Members
Forum Members
Posts: 17
Joined: Thu Apr 26, 2007 10:02 am

Re: Different backgrounds for main menu items

Post by hadion »

thanks all  ;D applaud
faglork

Re: Different backgrounds for main menu items

Post by faglork »

neophron wrote:

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;
Save the new tag. Go to your template and make this:
Thats all. Now every page will have a personal body class.

neophron
Yeah, but he wanted a class indicating just the TOP LEVEL categories. So you have to change the last line to

Code: Select all

echo $classes[0];
hth,
Alex
faglork

Re: Different backgrounds for main menu items

Post by faglork »

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:

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';
}
Now, in your page template in the HEADER DIV you use

Code: Select all

<h1><a style="background-image: url({bgimage};" href="/">Your Title goes here</a></h1>
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
Last edited by faglork on Fri Nov 23, 2007 12:55 pm, edited 1 time in total.
User avatar
lollipop27
Forum Members
Forum Members
Posts: 237
Joined: Wed Sep 12, 2007 4:09 pm

Re: Different backgrounds for main menu items

Post by lollipop27 »

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....
faglork

Re: Different backgrounds for main menu items

Post by faglork »

lollipop27 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?
Yes. The whole list is in the "classes" array ... just find out the length of the array, and then check for
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.
User avatar
lollipop27
Forum Members
Forum Members
Posts: 237
Joined: Wed Sep 12, 2007 4:09 pm

Re: Different backgrounds for main menu items

Post by lollipop27 »

thanks... great!!!

It works....

Larissa
streever

Re: Different backgrounds for main menu items

Post by streever »

oops

I actually wrote a plugin called "sectiontitle" that can give you an up level title.

check it in dev.cmsmadesimple.org
declanreynolds

Re: Different backgrounds for main menu items

Post by declanreynolds »

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'?
faglork

Re: Different backgrounds for main menu items

Post by faglork »

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.
Double-check the SERVER PATH:

Code: Select all

$filename = '/server/path/to/your/uploads/images/backgrounds/'.$picname.'.jpg';
this is something like
/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
declanreynolds wrote:
if the alias is 'aboutus' then do I simply call the image 'aboutus.jpg'?
Yes. All lower case.

hth,
Alex
declanreynolds

Re: Different backgrounds for main menu items

Post by declanreynolds »

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.
faglork

Re: Different backgrounds for main menu items

Post by faglork »

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';
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.

Cheers,
Alex
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Different backgrounds for main menu items

Post by calguy1000 »

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:

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}
[edit]

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>
in the body of your page template.... and set the background image, or background color any way you wanted for each root page.
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.
Post Reply

Return to “Layout and Design (CSS & HTML)”