News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Use a different background per board, with only 1 theme

Started by 1MileCrash, November 24, 2007, 05:13:15 PM

Previous topic - Next topic

1MileCrash

As answered in This topic.

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.
The only thing php can't do is tell you how much milk is left in the fridge.



codenaught

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. :)
Dev Consultant
Former SMF Doc Coordinator

1MileCrash

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"?
The only thing php can't do is tell you how much milk is left in the fridge.



SleePy

Tippmaster,

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

Of course you need to make sure that $board is globalized.
Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

karlbenson

#4
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
}

falguni1

this is very important and useful

can you make a mod and submit to mod site.

Akatsuki_dawn

Got a game console? Wanna hack it to play games for free? Need help hacking it? Get help, tutorials, music, games, and much more for every game console for free at my forum.

www.pspiso.smf4u.com

Join today!

softtouch

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


karlbenson

@Softtouch
Your right

I edited and corrected my example above. (it had an extra closing parenthesis)

MinasC

Wow , Tippmaster and Karlbenson that is really great ! thnx a lot !

jackregan

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.
Bible Study, Catholic News, Youth Group Stuff (my humble attempt at an SMF site... I'm grateful to the amazing people who have made SMF what it is!!

1MileCrash

The only thing php can't do is tell you how much milk is left in the fridge.



@rjen

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?
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

Advertisement: