News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Can boards have different colors?

Started by Segnali, February 17, 2018, 10:40:15 AM

Previous topic - Next topic

Segnali

I mean...I'd like to have some boards with different colors from the rest.

Is that possible?

Thanks

Aleksi "Lex" Kilpinen

What exactly? The Board title on index, the theme inside the board?
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

drewactual

#2
i do this with an included file, and which can be a full out css file or a simple banner for specific boards...

the concept is super simple....

in your index.php, (or even your boardindex or messageindex depending on what you're trying to accomplish), you plop the include as:

include('{link to the name of your php file with the alterations}');


for instance, i have that^ parked just under my header in my index.template for a board specific header image.

the file you want to make that's external to the theme should be constructed as such:

<?php
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' )  || ( isset($board) && $board == '1' )) {
  echo 
'<div id="barz"><img src="some.img"/></div>'; }

if(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {
  echo 
'<div id="barz"><img src="someother.img"/></div>'; }

if(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '3' ) || ( isset($board) && $board == '3' )) {
  echo 
'<div id="barz"><img src="yetanother.img"/></div>'; }

if(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '4' ) || ( isset($board) && $board == '4' )) {
  echo 
'div id="barz"><img src="adifferent.img"/></div>'; }

if(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '5' ) || ( isset($board) && $board == '5' )) {
  echo 
'<div id="barz"><img src="onemoredifferent.img"/></div>'; }
?>



....... == '5' ) || ( isset($board) && $board == '5' )) {
  ..... '<div id="barz"><img src="onemoredifferent.img"/></div>.....

as you can see in bold blue, these are simple images in a div in this script, but you can use html however you want it- it could certainly be CSS...

the bold red part: this is the board name, which is a number you want the script to be different in.  otherwise, (if not defined) it uses what's in the index.template (or whatever theme file you're using this in) file. 

the beauty in this is the simplicity, and by using 'include' as opposed to 'require', if it skips over it for some strange reason it won't 'break' the page.  furthermore, the only things that are different are defined, NOT the entire theme (if using a different theme) or a completely new stylesheet... you only have to introduce the changed parts...

as an example for background color (and meaning you'd want to place the php include in your head of index.template) :


if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' ) || ( isset($board) && $board == '1' )) {
  echo '<style>body{background-color:red;}</style>'; }

if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {
  echo '<style>body{background-color:blue;}</style>'; }


for something THAT^ simple (just the color or the body element), you can just add that^ to your index.template between the head tags... you gotta still define the board name (what number or name shows up in the URL when you navigate to that board)


as you can imagine, this little script via include can be used for all kinds of stuff such as advertisements, informational splashes for specific pages/boards, or just about anything else...

butch2k

another less intrusive way would be to add a class to the body.

Exemple for default theme

replace
echo '
</head>
<body>';


by
global $board;
echo '
</head>
<body class="'.(isset($board)?"board_".$board:"").'">';


and in the index.css file, if you which to change body's background color for board 10 and 15

.board_10{
background-color:#c25;
}
.board_15{
background-color:#ddd;
}


Segnali

Quote from: Aleksi "Lex" Kilpinen on February 17, 2018, 10:44:41 AM
What exactly? The Board title on index, the theme inside the board?

the background color like here is nearly white or grey...what if we wanted only this section to have green or blue or black background?

Steve

Butch 2k's post answers your question.

Drewactual's may as well but I'm not a coder so I'd go with butch's personally.
DO NOT pm me for support!

Segnali

Quote from: butch2k on February 18, 2018, 03:58:35 AM
another less intrusive way would be to add a class to the body.

Exemple for default theme

replace
echo '
</head>
<body>';



in which file of the default theme do I need to edit that?


Quote from: butch2k on February 18, 2018, 03:58:35 AM
and in the index.css file, if you which to change body's background color for board 10 and 15

.board_10{
background-color:#c25;
}
.board_15{
background-color:#ddd;
}



are:

#c25
#ddd

just two examples? Where can I find codes for other colors?

Thank you

butch2k

edit the index.template.php

Those colors are example, google "html colors" for color codes.

Steve

DO NOT pm me for support!

skb

I use a different theme for Private Boards. That way it's a whole new environment not just the background colour.

SMF 2.1.4 / TP 2.2.2

Segnali

Quote from: skb on March 31, 2018, 11:29:55 PM
I use a different theme for Private Boards. That way it's a whole new environment not just the background colour.

how can you use 2 different themes at the same time?

thank you

Segnali

Quote from: butch2k on February 18, 2018, 03:58:35 AM

and in the index.css file, if you which to change body's background color for board 10 and 15

.board_10{
background-color:#c25;
}
.board_15{
background-color:#ddd;
}




I suppose you are talking about the file in css directory.

It has more than 3000 lines...where exactly should I add those 2 lines?

I need to change background color for board 94 and 106

Thanks

butch2k

Add it at the bottom, just change the number after board_ to match the ones you need to change.

Segnali

Quote from: butch2k on April 01, 2018, 04:21:49 AM
Add it at the bottom, just change the number after board_ to match the ones you need to change.

Done but it did not work, nothing happened.  :(




Illori

Quote from: Segnali on April 01, 2018, 02:08:59 AM
Quote from: skb on March 31, 2018, 11:29:55 PM
I use a different theme for Private Boards. That way it's a whole new environment not just the background colour.

how can you use 2 different themes at the same time?

thank you

if you edit the board in the admin panel, it will have an option for you to select a theme for that board. no code edits required just for you to have more then 1 theme installed.

Segnali

Quote from: Illori on April 01, 2018, 06:57:50 AM
Quote from: Segnali on April 01, 2018, 02:08:59 AM
Quote from: skb on March 31, 2018, 11:29:55 PM
I use a different theme for Private Boards. That way it's a whole new environment not just the background colour.

how can you use 2 different themes at the same time?

thank you

if you edit the board in the admin panel, it will have an option for you to select a theme for that board. no code edits required just for you to have more then 1 theme installed.

right...I see the option, I think I'll go with that...cheers

Gwenwyfar

That will work well if you want different themes in each board, not if you just want to have different colors of the same theme. You can duplicate the theme and modify it too, but at the end of the day it's going to be much more troublesome to maintain and not any easier to edit the colors.
"It is impossible to communicate with one that does not wish to communicate"

Segnali

Quote from: Gwenwyfar on April 01, 2018, 08:10:50 AM
That will work well if you want different themes in each board, not if you just want to have different colors of the same theme. You can duplicate the theme and modify it too, but at the end of the day it's going to be much more troublesome to maintain and not any easier to edit the colors.

I guess you're right...just installed a new theme and it's already giving me issues.


Translated from Italian:

Error when scanning the template!

A problem occurred loading the model or translation file /Themes/Karanlik-Lord/languages/ThemeStrings.english.php. Check the syntax of the file and try again - pay attention to apostrophes ('): often they have to be preceded by the escape character (\). To view more detailed information about the error, try accessing the file directly. You can also try reloading the page or use the default theme.
syntax error, unexpected 'global' (T_GLOBAL)

Translated with www.DeepL.com/Translator

drewactual

ive been using this now for a couple months, and i really appreciate how clean it works.  here is where i shared it elsewhere here, and so i don't have to type it out again: 

Quote from: drewactual on February 20, 2018, 12:26:56 PM
it doesn't get a whole lot easier than this.   this is a variant of something i picked up here some time back, but can't recall where/who from.  All i did was intro the php include and external file, as well as multiple's by using the elseif operator.

you can use this however you see fit- and it works cleanly in many ways to include full out 'board sensitive' css or simple images... I use it to present a different header image for several boards... simply use a php include to a new file you're about to create... in that file:



<?php
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' ) || ( isset($board) && $board == '1' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '3' ) || ( isset($board) && $board == '3' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '4' ) || ( isset($board) && $board == '4' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '5' ) || ( isset($board) && $board == '5' )) {
  echo 
'{whatever you want to inject}'; }
  
 else {
  echo 
'{whatever your base is}'; }
?>




the area {whatever you want to inject} is where your changes are offered.  you can use css, html, or even another php include if you want (such as you may if you're 'injecting' a large amount of info such as a big css or a big js)...

the area {whatever your base is} is what you want to appear (inject) on a 'standard' page- or left blank between the ' ' to not do anything.... it's there though, if you need it. 

the board numbers you should match up with the boards you intend to use this on.... i just numbered them 1, 2, 3, 4, and 5...

the function is injected on either your index.template, boardindex.template, or message.index template (adjusting accordingly) by a simple php include- such as:
include('url to the file you just made');

it's nice that it's an 'include' as it won't break anything if it doesn't work- such as jacked up code (if it's js or php you're 'injecting' that has a syntax error).  if it was 'require' (which you can use, but i wouldn't rec it) it would break the render if it tripped over itself.

at any rate, this is a useful little script to do (if i understand correctly) what you want to accomplish.  I hope you find purpose for it!



you can interject into individual boards whatever you want with this little script- and keep up with it easier on your server by having filenames/directories appropriately set... because you use it as an 'include' as opposed to a 'require', if something goes wonky it'll resort to the base instructions instead of freezing up.  my sig has a site with it in use- go to different 'power five' boards and look at the top banner.

i'm also going to  - before next season begins- us this same concept but instead of boards have it sniff if user is a member/logged in... if they aren't, they're gonna carry the water for the site's earnings (adverts), but if they're registered and logged in they'll be protected from (most) the ads.... 

Kindred

You do realize that the ad manager mod already handles that?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: