MyBB Community Forums

Full Version: how do I code conditional {$colspan} for a specific theme?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is the code in forumdisplay.php which sets the $colspan variable. The condition is based on the presence or lack of ratings. The last part increments the column count for mod editing.


if($mybb->settings['allowthreadratings'] != 0 && $foruminfo['allowtratings'] != 0 && $fpermissions['canviewthreads'] != 0)
{
	$lang->load("ratethread");

	switch($db->type)
	{
		case "pgsql":
			$ratingadd = "CASE WHEN t.numratings=0 THEN 0 ELSE t.totalratings/t.numratings::numeric END AS averagerating, ";
			break;
		default:
			$ratingadd = "(t.totalratings/t.numratings) AS averagerating, ";
	}

	$lpbackground = "trow2";
	eval("\$ratingcol = \"".$templates->get("forumdisplay_threadlist_rating")."\";");
	eval("\$ratingsort = \"".$templates->get("forumdisplay_threadlist_sortrating")."\";");
	$colspan = "7";
}
else
{
	if($sortfield == "averagerating")
	{
		$t = "t.";
		$sortfield = "lastpost";
	}
	$ratingadd = '';
	$lpbackground = "trow1";
	$colspan = "6";
}

if($ismod) 
{ 
    ++$colspan; 
} 


I have a theme that adds a column, but do not want to modify the default theme. How can I add a conditional increment based on a specific theme id, or better a named theme?

My goal is to preserve a legacy theme from 1.6.8 after update to 1.8.9 (and beyond). I've seen discussion elsewhere in the MyBB community where (1) using a plugin for theme conditions, (2) hard coding the table in the theme, or (3) modifying the php source works.

Suggestions?
Thanks for your help


Fixed by finding the excellent variable reference referred in other posts.
Then I made a core file edit by adding to forumdisplay.php


if($theme['tid'] = "8") // added for extra column in old black times 
{ 
    ++$colspan; 
}


Tested and verified by both moderator and non-moderator users on both default and legacy themes.
In any forum update, I will have to manually add the mod code after verifying the theme id is still 8.

I've answered my own question as encouragement for others to experiment, preferably on a test forum before making it live.