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

drewactual

I do.. And I own both smfhacks and smfpacks ad handler... But neither suite my needs, and both argue with php7.  I dont need anything that heavy, quite frankly.   Theyre both good in different ways and I'm certain I'll use them on other ventures, but speed, clean, and heavy traffic are my concerns on the page I ised as an example.  This little script is a champ for that.

Gwenwyfar

butch's solution is good, 2.1 already does that by default. But you'll need to use the right variable. I can take a look at it later if no one else does.
"It is impossible to communicate with one that does not wish to communicate"

Segnali

Quote from: Gwenwyfar on April 01, 2018, 10:36:35 PM
butch's solution is good, 2.1 already does that by default. But you'll need to use the right variable. I can take a look at it later if no one else does.

I am stuck at SMF 2.0.5

If I try to upgrade I get errors and after all the mods I added, I really don't want to mess with it.

Illori

if you are still running 2.0.5, you are open to possibly being hacked. you really need to take time to upgrade to 2.0.15 for security and php compatibility.

Segnali

Quote from: Illori on April 02, 2018, 05:06:45 AM
if you are still running 2.0.5, you are open to possibly being hacked. you really need to take time to upgrade to 2.0.15 for security and php compatibility.

I backup once a week. Being hacked cannot be 100% prevented even by running NASA software...

I just need butch's solution to work and it doesn't on my forum  :-\

Kindred

and yet... by running a version 10 releases behind, you are pruposefully exposing your site and your users to potential hack/breaches.

You need to update ASAP
Сл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."

Steve

Segnali, listen to the man. Why make it easier for hackers?
DO NOT pm me for support!

butch2k

Could you post the index.template.php of your current theme ?

Segnali

Quote from: Steve on April 07, 2018, 10:08:48 AM
Segnali, listen to the man. Why make it easier for hackers?

alright I'll do it ASAP.

P.S. I love your avatar  :)

Segnali

Quote from: butch2k on April 07, 2018, 10:23:25 AM
Could you post the index.template.php of your current theme ?

sure, here it is, thank you

butch2k

Could you try modifying your css like this:

.board_94{
background: #c25 url(../images/theme/backdrop.png) repeat-x;
}
.board_106{
background: #ddd url(../images/theme/backdrop.png) repeat-x;
}

if you need the backdrop image.

else
.board_94{
background: #c25;
}
.board_106{
background: #ddd;
}

Segnali

what do you mean by backdrop image? sorry English is not my first language.

Thank you

Segnali

Quote from: butch2k on April 08, 2018, 06:58:58 AM

.board_94{
background: #c25;
}
.board_106{
background: #ddd;
}


tried the latter with color #0C090A for board #106 but did not work, nor worked #c25 for board #94  :-\

drewactual

humor me?
in your index.template, do:

before:

echo '
</head>


add:

//board color adjustment script
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '94' )  || ( isset($board) && $board == '94' )) {
  echo '<style> body\{background:#c25\}</style>'; }
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '106' ) || ( isset($board) && $board == '106' )) {
  echo '<style>body\{background:#ddd\}</style>'; }
//end board color adjustment script


lose the css adjustments...

if you need/want to change colors on more boards, simply copy/paste one of the two lines above and change the board number and the color code... it's really about that simple. 

i don't have means to test it, but this or something very close should do the trick you seek.  the '\' prior to the '{' or '}' is required, i do think, due to it having a specific purpose within php... if this doesn't do what you need, no harm no foul, remove it and go with the CSS once you iron it out... don't get me wrong, i love css and what it can do- but there is little comparison of functionality to just code it in... 

butch2k

 Segnali is it possible to get a link to your board ? I need to have a look to understand what's going on.

Segnali

#35
Quote from: butch2k on April 12, 2018, 05:04:34 PM
Segnali is it possible to get a link to your board ? I need to have a look to understand what's going on.

I created a copy on a test site so we can play with the copy.

http://www.evotrading.it/forum/index.php

The boards # in the css files have been changed in the test copy because the others are for private boards.

New numbers are 98 & 103

Thank you

P.S. I know I need to update the forum software so I will get on this week starting from that copy as well.

Gwenwyfar

You will have to edit your index.template to fix the variable you are using, change:

echo $context['html_headers'];

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


to

echo $context['html_headers'];

echo '
</head>
<body', (!empty($context['current_board']) ? ' class="board_'. $context['current_board'] .'"' : ''),'>';
"It is impossible to communicate with one that does not wish to communicate"

butch2k

Yes it should work, $board works on my forum probably because it is set by simpleportal at some previous point which might not be the case on pure SMF.

Advertisement: