You might want to assign $this->countModules('Top2A and Top2B and Top2C')
to a variable.
That's just for some readability. As for the PHP or statement, we use a double pipe ||
for that, not the word "or".
Also, note that $this->countModules() using 'and'/'or' in the parameter will return true or false, not the number of modules counted. If you want to count the total number of modules, you should use the '+' operator. (Just read that on http://docs.joomla.org/JDocumentHTML/countModules, so correct me if I am wrong :) )
So at the end of the day...:
$modRow2=""; //give it an initial value, then you don't need an else branch to give it this value, only a single if-statement to change it.
$modCellRow1=""; //also initialize this, for the same reason
$countMods=$this->countModules('Top2A + Top2B + Top2C'); //count total modules
if($countMods == 0)
{
$modRow2 = " hidden";
}
if ($countMods==2)
{
$modCellRow1="col2";
}
This code could be cleaner but I thought it might be better to keep it simple and readable instead.
Hope this helps! :)
EDIT:
Your update looks fine (after a quick read) :) Just a side note on the duplicate if-statements though, you could rather use switches instead - they make for cleaner code. For example:
instead of
if($countModsRow1 == 0) { $modRow1=" hidden"; }
if($countModsRow1 == 1) { $modCellRow1="col1"; }
if($countModsRow1 == 2) { $modCellRow1="col2"; }
if($countModsRow1 == 3) { $modCellRow1="col3"; }
use
switch($countModsRow1)
{
case 0:
$modRow1="hidden";
break;
case 1:
$modCellRow1="col1";
break;
case 2:
$modCellRow1="col2";
break;
case 3:
$modCellRow1="col3";
break;
default:
//do something if none of these cases are evalutated as being true
break;
}
It might look like a ton of code, but if your if-statements were to grow for some reason, they might become difficult to manage in the future. Some resource on the switch if you feel the need to read up on it: PHP Switch
EDIT:
You were then correct initial post: to check if there are modules in each position (not worrying about how many there are), you would use something like $this->countModules('Top2A and Top2B and Top2C')
. If that evaluates to 0 (false), then there are no modules in those positions, otherwise there is at least one module in EACH position.
If you want to check if there is a module in one or more of those positions, you would use $this->countModules('Top2A or Top2B or Top2C')
. If that evaluates to 0 (false), then none of those positions contain modules, otherwise AT LEAST one of then does.
I hope that helps a bit more, sorry for the confusion