Advertisement:

Author Topic: Use a different background per board, with only 1 theme  (Read 15110 times)

Offline 1MileCrash

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,188
Use a different background per board, with only 1 theme
« on: November 24, 2007, 05:13:15 PM »
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.

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

And delete that, and replace with:

Code: [Select]
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:
Code: [Select]
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.
« Last Edit: November 24, 2007, 05:20:22 PM by akabugeyes »
The only thing php can't do is tell you how much milk is left in the fridge.



Offline codenaught

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 14,653
  • Gender: Male
  • Formerly Known As akabugeyes
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

Offline 1MileCrash

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,188
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.



Offline SleePy

  • Site Team Lead
  • SMF Master
  • *
  • Posts: 30,373
  • Gender: Male
  • Thats his happy face.
    • jdarwood007 on GitHub
    • @jdarwood on Twitter
    • SleePy Code - My personal site
Re: Use a different background per board, with only 1 theme
« Reply #3 on: December 12, 2007, 10:48:07 PM »
Tippmaster,

Code: [Select]
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
Support the SMF Support team!
Profiles:
GitHub

Offline karlbenson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,629
  • Gender: Male
    • Criminal Brief UK
Re: Use a different background per board, with only 1 theme
« Reply #4 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
Code: [Select]
<body>
Code: [Select]
<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
}
« Last Edit: January 10, 2008, 06:15:23 PM by karlbenson »

Offline falguni1

  • Full Member
  • ***
  • Posts: 652
  • Gender: Female
  • http://beautymakeupdivas.com/
Re: Use a different background per board, with only 1 theme
« Reply #5 on: December 21, 2007, 03:13:30 AM »
this is very important and useful

can you make a mod and submit to mod site.

Offline Akatsuki_dawn

  • Newbie
  • *
  • Posts: 8
  • Gender: Male
Re: Use a different background per board, with only 1 theme
« Reply #6 on: December 23, 2007, 05:01:42 PM »
Thanks a lot for that info. It was quite helpful.
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.

hxxp:www.pspiso.smf4u.com [nonactive]

Join today!

Offline softtouch

  • Jr. Member
  • **
  • Posts: 105
Re: Use a different background per board, with only 1 theme
« Reply #7 on: January 01, 2008, 05:39:35 AM »

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

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

It just gives me a template parse error...

Offline Jalkson

  • Jr. Member
  • **
  • Posts: 173
  • Gender: Male
Re: Use a different background per board, with only 1 theme
« Reply #8 on: January 10, 2008, 05:44:38 PM »
Very nice, works well. =]

Offline karlbenson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,629
  • Gender: Male
    • Criminal Brief UK
Re: Use a different background per board, with only 1 theme
« Reply #9 on: January 10, 2008, 06:16:11 PM »
@Softtouch
Your right

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

Offline MinasC

  • Full Member
  • ***
  • Posts: 423
  • Gender: Male
    • The Copycat
Re: Use a different background per board, with only 1 theme
« Reply #10 on: January 14, 2008, 11:44:13 AM »
Wow , Tippmaster and Karlbenson that is really great ! thnx a lot !

Offline jackregan

  • Jr. Member
  • **
  • Posts: 167
  • Gender: Male
Re: Use a different background per board, with only 1 theme
« Reply #11 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.
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!!

Offline 1MileCrash

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,188
Re: Use a different background per board, with only 1 theme
« Reply #12 on: January 18, 2008, 11:48:14 PM »
Try $_REQUEST['action'] instead?
The only thing php can't do is tell you how much milk is left in the fridge.



Online @rjen

  • Full Member
  • ***
  • Posts: 509
  • Gender: Male
Re: Use a different background per board, with only 1 theme
« Reply #13 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.

Code: [Select]
<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.0 with Tinyportal 1.6.4 at www.fjr-club.nl
Testing SMF 2.1 RC2 with Tinyportal at http://test2.fjr-club.nl/