Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: 1MileCrash on November 24, 2007, 05:13:15 PM

Title: Use a different background per board, with only 1 theme
Post by: 1MileCrash on November 24, 2007, 05:13:15 PM
As answered in This topic (http://www.simplemachines.org/community/index.php?topic=207379.0;topicseen).

This is for those of you who want to change the look of a board, but do not want to instal a whole 'nother theme just to do this.

For example, if you want the background changed, link colors, font size, etc.

First thing you need to do is open up index.template.php

Find where the stylesheet is externally linked to.

echo '
   <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?fin11" />


And delete that, and replace with:

if(!empty($GLOBALS['board']))
{
echo'<link rel="stylesheet" type="text/css" href="',$theme_url,'/style',$GLOBALS['board'],'.css?fin11" />';
}
else
{
echo'<link rel="stylesheet" type="text/css" href="',$theme_url,'/style.css?fin11" />';
}

echo'


With this setup, a new style.css file will be used for each board. For example, style5.css is used in board 5.

So, you need to copy the style.css file for each board you have, naming it "style[id].css", then you can make your changes for each board.

This is best suited for people who want a different background for almost every board.

If you want to change style for only one board, you could do something like this instead:

if(!empty($GLOBALS['board']) && $GLOBALS['board'] == '5')
{
echo'<link rel="stylesheet" type="text/css" href="',$theme_url,'/style',$GLOBALS['board'],'.css?fin11" />';
}
else
{
echo'<link rel="stylesheet" type="text/css" href="',$theme_url,'/style.css?fin11" />';
}

echo'


This would result in ONLY board 5 being changed, it would use style5.css, while the rest of the boards would still use the normal style.css.

Feel free to post here if you have any questions.
Title: Re: [tips and tricks] - Use a different background per board, with only 1 theme
Post by: codenaught on November 24, 2007, 05:19:39 PM
Nice job, I remember doing something similar to this once.

A few things...

Any reason why you don't use $context['current_board'] instead of $GLOBALS['board']?

Also I would recommend perhaps doing a file_exists() check so you are not forced to have a style[id].css file for every single board if you only want it for say 3 boards.

Moved to Tips and Tricks. :)
Title: Re: [tips and tricks] - Use a different background per board, with only 1 theme
Post by: 1MileCrash on November 24, 2007, 05:28:28 PM
Quote from: akabugeyes on November 24, 2007, 05:19:39 PM
Nice job, I remember doing something similar to this once.

A few things...

Any reason why you don't use $context['current_board'] instead of $GLOBALS['board']?

Also I would recommend perhaps doing a file_exists() check so you are not forced to have a style[id].css file for every single board if you only want it for say 3 boards.

Moved to Tips and Tricks. :)

Yeah, you could use $context too for the first method (you can't check the value of $context['current_board'] on index.template.php, only check if it's empty, which just means that you aren't on a board in the first place), but i adapted it from something else (displaying news/key stats/etc or hiding it in a certain board) where it can't be used, since all you can do is check if $context['current_board'] is empty on index.template.

file_exist() is something i don't really know much about unfortunately. Is it just something like "if file exists, use style',$GLOBALS['board'],'.css, if false use style.css"?
Title: Re: Use a different background per board, with only 1 theme
Post by: SleePy on December 12, 2007, 10:48:07 PM
Tippmaster,

if(file_exists($settings['theme_dir'] . /style . $board . '.css))

Of course you need to make sure that $board is globalized.
Title: Re: Use a different background per board, with only 1 theme
Post by: karlbenson on December 12, 2007, 10:57:29 PM
If it were just the background that was to be changed.

Wouldn't it be infinitely easier all round to
find in Index.template.php
<body>

<body id="'. ( empty($context['current_board']) ? 'default' : 'board_'. $context['current_board'] .)'">

Then in ONE single css file (style.css)

#default body
{
background-image etc
}

#board_1 body
{
etc
}
Title: Re: Use a different background per board, with only 1 theme
Post by: falguni1 on December 21, 2007, 03:13:30 AM
this is very important and useful

can you make a mod and submit to mod site.
Title: Re: Use a different background per board, with only 1 theme
Post by: Akatsuki_dawn on December 23, 2007, 05:01:42 PM
Thanks a lot for that info. It was quite helpful.
Title: Re: Use a different background per board, with only 1 theme
Post by: softtouch on January 01, 2008, 05:39:35 AM
Quote from: karlbenson on December 12, 2007, 10:57:29 PM

find in Index.template.php
[/code]<body>[/code]

<body id="'. ( empty($context['current_board']) ? 'default' : 'board_'. $context['current_board'] ) .)'">

It just gives me a template parse error...
Title: Re: Use a different background per board, with only 1 theme
Post by: Jalkson on January 10, 2008, 05:44:38 PM
Very nice, works well. =]
Title: Re: Use a different background per board, with only 1 theme
Post by: karlbenson on January 10, 2008, 06:16:11 PM
@Softtouch
Your right

I edited and corrected my example above. (it had an extra closing parenthesis)
Title: Re: Use a different background per board, with only 1 theme
Post by: MinasC on January 14, 2008, 11:44:13 AM
Wow , Tippmaster and Karlbenson that is really great ! thnx a lot !
Title: Re: Use a different background per board, with only 1 theme
Post by: jackregan on January 16, 2008, 02:07:46 PM
I am really enjoying messing around with this. It's a great tip. thank you :D

One question though...

How do I make the background different for things like profiles or memberlist etc? i.e. non-boards.

I guess it's something like

if ($context['current_action'] == 'profile')

but I can't work it out exactly.
Title: Re: Use a different background per board, with only 1 theme
Post by: 1MileCrash on January 18, 2008, 11:48:14 PM
Try $_REQUEST['action'] instead?
Title: Re: Use a different background per board, with only 1 theme
Post by: @rjen on March 06, 2016, 03:34:57 PM
I have been trying this trick in my 2.0.11 forum using my own Theme, which is a tweaked Curve variation.

I made this code change to use an alternate css file (index_club.css) for the boards that are in the array.


<head>';

// The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
// Deactivated code

// echo '
// <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />

// Added code
// In order to pick an alternate Stylesheet per board
$club = array('44','5','6','45','9','64','60','62','53','61','54','7','55','10','56','36','13','11','12','27','29','30','14','15','16','17');

if(!empty($GLOBALS['board']) &&  in_array($GLOBALS['board'], $club))
{
echo'<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'],'_club.css?fin20" />';
}
else
{
echo'<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />';
}
// Einde invoeging FJR

echo'<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/responsive', $context['theme_variant'], '.css?fin20" />';


It works mostly as I want, but I have one problem. Hoping that someone can help me sort this out.

When I am in the Board Index the default styesheet is used, which is correct.
Now that I select one of the board - for example Board 10 - the board index for this board is showing with the default css. I was expecting the alternate since board 10 is in the array.

Now selecting a topic IN board 10 the css changes to the alternate.

I was kind of hoping that the topic list in the board would also be shown with the alternate css.

Now I find that when I display a board that has child boards (board 44 has two child boards, board 4 and board 5) the alternate css IS shown for board index in board 44 but not in 4 and 5, yet all topics in all three boards use the alternate boards.

How can I set it up so that all board indexes for the relevant boards will use the alternate css? Maybe the $GLOBALS['board'] variable is filled differently in case a board has no child boards?