Jump to content

Need to add an extra column class to my php code


tomkilbourn

Recommended Posts

Hello forum  :)

 

I need some help modifying a secton of PHP code which is used in a module for displaying news article headlines.

 

The code snippet allows for either a single-column or a two-column layout.

 

What I would love to do is add a THIRD column to produce a 3 column layout if desired.

 

The single-column layout class is called "singleColumn", and the two-column layout class is called "firstColumn" and "secondColumn".

 

I have this snippet from my default.php module code, but I don't really know how to add the option for a third column, can anyone help, I would be very greatful  :)

 

$singleColumn = '';
$firstColumn = $secondColumn = '';
for ($b = 0; (($this->news_amount - ($b * $this->news_column)) > 0); $b++) { 

   for ($c = 0; $c < $this->news_column; $c++) { 

      if ($this->news_column == 1) { 
         $div_class = 'single_column_class';  
      } elseif ($this->news_column == 2) { 
         $div_class = ($c == 0) ? 'first_column_class' : 'second_column_class'; 
      } 
      
      $column = ($b * $this->news_column) + $c; 

Im not sure how to code to allow for a third column, could anyone help me out?

Wouldn't this work?

 

$singleColumn = '';
$firstColumn = $secondColumn = '';
for ($b = 0; (($this->news_amount - ($b * $this->news_column)) > 0); $b++) { 

   for ($c = 0; $c < $this->news_column; $c++) { 

      if ($this->news_column == 1) { 
         $div_class = 'single_column_class';  
      } elseif ($this->news_column == 2) { 
         $div_class = ($c == 0) ? 'first_column_class' : 'second_column_class'; 
      } elseif ($this->news_column == 3) {
         $dir_class = 'third_column_class';
      }
      
      $column = ($b * $this->news_column) + $c; 

I will give it a go, but wouldn't I have to declare the thirdColum variable first? E.g. -

$thirdColumn = '';

or maybe

$firstColumn = $secondColumn = thirdColumn = '';

 

Ive been trying to add a line something like this -

elseif ($this->news_column == 3) {
         $div_class = 'first_column_class : second_column_class : third_column_class';
      }

 

But the code isn't right and gives an error, it doesnt like the 3 classes together.

 

If this is any help, here is the full script including the code for outputting the columns and classes -

 

<?php 
// no direct access 
defined('_JEXEC') or die('Restricted access'); 
$singleColumn = '';
$secondColumn = $firstColumn = '';
$firstColumn = $secondColumn = $thirdColumn = '';
for ($b = 0; (($this->news_amount - ($b * $this->news_column)) > 0); $b++) { 

   for ($c = 0; $c < $this->news_column; $c++) { 

      if ($this->news_column == 1) { 
         $div_class = 'single_column_class';  
      } elseif ($this->news_column == 2) { 
         $div_class = ($c == 0) ? 'second_column_class' : 'first_column_class'; 
      } 
      
      $column = ($b * $this->news_column) + $c; 

//Start Single Column here      
   	
 { 
      //Start SingleColumn Rounded Flexable Corners option
         if ($this->singlerounded) { 
            $singleColumn .=  '<div class="roundedflexable"><div><div><div>'."\n"; 
            if (isset($news_code_html_tab[$column])) { 
               $singleColumn .= $news_code_html_tab[$column]; 
            } 
         } 

	 //Start SingleColumn Rounded Fixed Corners option
	 elseif ($this->singleroundedfixed) { 
            $singleColumn .=  '<div class="gk_round_fixed"><div>'."\n";          
            if (isset($news_code_html_tab[$column])) { 
               $singleColumn .= $news_code_html_tab[$column]; 
            } 
         } 

	  //Start SingleColumn Squared Corners option 
	 elseif ($this->singleesquaredcorners) { 
            $singleColumn .=  '<div class="squared">'."\n";       
            if (isset($news_code_html_tab[$column])) { 
               $singleColumn .= $news_code_html_tab[$column]; 
            } 
         } 
	 //End SingleColumn Squared Corners option 
	   if ($this->singlesquaredcorners) { 
            $singleColumn .=  '</div>'."\n"; 
         } 
	  		
	 //End SingleColumn Rounded Fixed Corners option
         elseif ($this->singleroundedfixed) { 
            $singleColumn .=  '</div></div>'."\n"; 
         } 
	 //End Single Column Rounded Flexable Corners option
         elseif ($this->singlerounded) { 
            $singleColumn .=  '</div></div></div></div>'."\n"; 
         } 
          		 
      } 
//End SingleColumn here


//Start First Column here    
      if ($c == 0 && $this->news_column > 1) {
	  
      //Start First Column Rounded Corners option
         if ($this->firstrounded) { 
            $firstColumn .=  '<div class="roundedflexable"><div><div><div>'."\n"; 

                   
            if (isset($news_code_html_tab[$column])) { 
               $firstColumn .= $news_code_html_tab[$column]; 
            } 
         } 
  //Start first Column Squared Corners option 
	 elseif ($this->firstsquaredcorners) { 
            $firstColumn .=  '<div class="squared">'."\n"; 

                   
            if (isset($news_code_html_tab[$column])) { 
               $firstColumn .= $news_code_html_tab[$column]; 
            } 
         } 
	//End First Column Rounded Corners option
         if ($this->firstrounded) { 
            $firstColumn .=  '</div></div></div></div>'."\n"; 
         } 
	//End first Column Squared Corners option
	   elseif ($this->firstsquaredcorners) { 
            $firstColumn .=  '</div>'."\n"; 
         } 
	  
      } 
//End first Column here

/////////////////////////////////////////////     

//Start Second Column here
      if ($c != 0){ 
  
      //Start Second Column Rounded Corners option
         if ($this->secondrounded) { 
            $secondColumn .=  '<div class="roundedflexable"><div><div><div>'."\n"; 

            if (isset($news_code_html_tab[$column])) { 
               $secondColumn .= $news_code_html_tab[$column]; 
            } 
         } 
  //Start second Column Squared Corners option 
	  elseif ($this->secondsquaredcorners) { 
            $secondColumn .=  '<div class="squared">'."\n"; 

                   
            if (isset($news_code_html_tab[$column])) { 
               $secondColumn .= $news_code_html_tab[$column]; 
            } 
         } 

	//End Second Column Rounded Corners option
         if ($this->secondrounded) { 
            $secondColumn .=  '</div></div></div></div>'."\n"; 
         } 

	//End Second Column Squared Corners option
		elseif ($this->secondsquaredcorners) { 
            $secondColumn .=  '</div>'."\n"; 
         } 

      } 
//End Second Column here 
   }   
}
//Display Output from First Column here
if (!empty($firstColumn)) 
{
echo '<div id="'.$this->first_module_id.'">'."\n"; 
echo $firstColumn; 
echo '</div>'; 
}
//End First Column
             
//Display Output from Second Column here
if (!empty($secondColumn)) 
{
echo '<div id="'.$this->second_module_id.'">'."\n"; 
echo $secondColumn; 
echo '</div>'."\n";  
}
//End Second Column     

//Display Output from Single Column here
if (!empty($singleColumn)) 
{
echo '<div id="'.$this->single_module_id.'">'."\n"; 
echo $singleColumn; 
echo '</div>'."\n";  
}
//End Single Column   
?> 

$div_class = 'first_column_class : second_column_class : third_column_class';

 

If you print this directly into the class attribute then you may use something like:

 

$div_class = 'column column-right';

 

.column { /*css rules for a column*/ }
.column-right { /*css rules for the right column (reminder: css rules from .column are already applied)*/ }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.