Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: 1MileCrash in November 24, 2007, 05:13:15 NACHMITTAGS

Titel: Use a different background per board, with only 1 theme
Beitrag von: 1MileCrash in November 24, 2007, 05:13:15 NACHMITTAGS
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.
Titel: Re: [tips and tricks] - Use a different background per board, with only 1 theme
Beitrag von: codenaught in November 24, 2007, 05:19:39 NACHMITTAGS
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. :)
Titel: Re: [tips and tricks] - Use a different background per board, with only 1 theme
Beitrag von: 1MileCrash in November 24, 2007, 05:28:28 NACHMITTAGS
Zitat von: akabugeyes in November 24, 2007, 05:19:39 NACHMITTAGS
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"?
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: SleePy in Dezember 12, 2007, 10:48:07 NACHMITTAGS
Tippmaster,

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

Of course you need to make sure that $board is globalized.
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: karlbenson in Dezember 12, 2007, 10:57:29 NACHMITTAGS
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
}
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: falguni1 in Dezember 21, 2007, 03:13:30 VORMITTAG
this is very important and useful

can you make a mod and submit to mod site.
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: Akatsuki_dawn in Dezember 23, 2007, 05:01:42 NACHMITTAGS
Thanks a lot for that info. It was quite helpful.
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: softtouch in Januar 01, 2008, 05:39:35 VORMITTAG
Zitat von: karlbenson in Dezember 12, 2007, 10:57:29 NACHMITTAGS

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...
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: Jalkson in Januar 10, 2008, 05:44:38 NACHMITTAGS
Very nice, works well. =]
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: karlbenson in Januar 10, 2008, 06:16:11 NACHMITTAGS
@Softtouch
Your right

I edited and corrected my example above. (it had an extra closing parenthesis)
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: MinasC in Januar 14, 2008, 11:44:13 VORMITTAG
Wow , Tippmaster and Karlbenson that is really great ! thnx a lot !
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: jackregan in Januar 16, 2008, 02:07:46 NACHMITTAGS
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.
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: 1MileCrash in Januar 18, 2008, 11:48:14 NACHMITTAGS
Try $_REQUEST['action'] instead?
Titel: Re: Use a different background per board, with only 1 theme
Beitrag von: @rjen in März 06, 2016, 03:34:57 NACHMITTAGS
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?