Page 1 of 1
[56K WARN] Alternating Thread Colours
Posted: Wed Dec 19, 2007 7:18 pm
by Crazygar
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Ok, I have the code;
Code: Select all
$bgcolor = "#E0E0E0"; // light gray
$row = mysql_stuff()
while($row = mysql_fetch_array($result)){
if ($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}
echo("<tr bgcolor=".$bgcolor."\"><td>\n");
Graciously supplied by someone here to alternate between the colour of my forum threads when viewing. I know that I have to alter something in "viewforum.php" where it begins to "echo" the table data for viewing. Here is my problem -- where? A little pointer would help greatly. Thanks.
Gary
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Dec 19, 2007 7:32 pm
by John Cartwright
What is your question? Where what?
Posted: Thu Dec 20, 2007 5:52 am
by Crazygar
What I would like to know is where to put this code in to have my threads alternate colours. I am under the assumption its either viewforum.php or viewtopic.php. I am at a loss where to insert the code to have this happen. I hope this clarifies things.
This is the code that is supposed to help my accomplish this task. This is one of the final "loose ends" I need to have this happen. Or does anyone know a hack or mod out there that can do this with more detailed instructions?
Like this example I found; (this is for phpBB2)
Having it going between the two colours makes everything so much better and much easier to read. I would appriciate any assistance in this matter.
Gary A.MacDonald
Posted: Thu Dec 20, 2007 7:03 am
by LiveFree
Generally speaking, you can use the modulus (%)
Code: Select all
$x = 2;
while (something()) {
if (($x % 2) == 0) {
# First background color
} else {
# Second background color
}
$x++;
}
Posted: Thu Dec 20, 2007 8:51 am
by feyd
There have been a bunch of threads about this sort of display formatting. Look around for "zebra".
Posted: Thu Dec 20, 2007 8:52 am
by Kieran Huggins
Not to be super picky or anything, but I really hate hard-coded row colours.
They're sort of a style thing (and should be), but CSS engines today don't properly support child selectors. Boo-urns.
You could supplement this deficiency as a behaviour in the meantime:
Code: Select all
$(function(){
$('.sometable tr:odd').css('background','#d0d0d0');
});
Posted: Thu Dec 20, 2007 8:57 am
by feyd
Kieran Huggins wrote:Not to be super picky or anything, but I really hate hard-coded row colours.
They're sort of a style thing (and should be), but CSS engines today don't properly support child selectors. Boo-urns.
You could supplement this deficiency as a behaviour in the meantime:
Code: Select all
$(function(){
$('.sometable tr:odd').css('background','#d0d0d0');
});
Or you could specify a class instead of a color in the code.

Posted: Thu Dec 20, 2007 9:02 am
by Kieran Huggins
I feel ways about non-semantic markup. Probably too many ways.
"odd" and "even" classes don't have any relevance to the data and are purely hackish CSS hooks. Yuck
I'll feel better after my morning coffee & enema.
Posted: Thu Dec 20, 2007 3:15 pm
by Crazygar
Ok. I like the CSS Route much better than hard coding it myself. I am at loss where to insert the ACTUAL code. If it were turned into a "CSS Behaviour", obviously, all I need to do is modify viewtopic.tpl than start fooling around with .php files. I'll do a search for "zebra" thanks for the quick tip.
Now that I am awake, alternating thread colours like this forum.
Gary
Posted: Thu Dec 20, 2007 3:33 pm
by Kieran Huggins
phpBB has odd/even functions built-in to their custom templating system, if that's what you're looking for. Take a look inside an existing phpBB template for an example.
Posted: Thu Dec 20, 2007 3:50 pm
by Crazygar
Kieran, I'm having a devil of a time with this. What template(s) would have this? A Google search returned the same results as to the other searches I've been doing on trying to locate this. All I want it do is alternate between;
Even Background-color #2d3446
Odd Background-color #3d475f
For my viewing the threads in my Forum. The function method sounds good. As it eliminates harding coding to a php file which other templates might share. With defining the function, obviously it is being placed within the "viewtopic.tpl" file, its just a matter of placement.
Code: Select all
$(function(){
$('.sometable tr:odd').css('background','#3d475f');
});
Even a CSS routine would be easier.
Code: Select all
tr:nth-child(even) {background: #2d3446}
tr:nth-child(odd) {background: #3d475f}
Its just the matter of "where" to place it and how to code into the appropriate file to get the output I desire. I've tried the Zebra Search and its rather "Cryptic" at best. My biggest problem is logical placement of the snippets of code to do the intended function.
I'm a little wet behind the ears in all this so I might need a more "precise" location and files to edit to perform the necessary task. I'm hunting for a good couple of starter books to get my down the php/phpBB2 road so I can stop bothering everyone with these questions.
Gary