...

View Full Version : Need help with php/joomla frontpage code please



moss2076
03-18-2009, 05:43 PM
Hello this is a question regarding php/html, so I am posting in the php forum firstly to see if any help can be suggested :)

I am using Joomla 1.5 to design my webpage. I have converted the entire from using Tables to using Divs/Css.

The last part which I need to convert is on the Frontpage, and is the two vertical columns which display leading articles. This is the only part which is still using tables. I want to convert the table and cell into divs, and keep the same 2-column layout.

The file is in my Joomla template directory - templates/myjoomlatest/html/frontpage/default.php

I want to convert the two-column section from tables to divs.
Here is a link to my page - http://www.tomsspecialreserve.co.uk/joomla
It is the 6 rounded corner articles in the middle.

Currently the html output using Firebug to view it is this -



<table width="100%">
<tbody>
<tr>

<td class="article_column" width="50%" valign="top">
<div class="contentpaneopen-tomsroundedcategory">
</div>
<div class="contentpaneopen-tomsroundedcategory">
</div>
<div class="contentpaneopen-tomsroundedcategory">
</div>
</td>

<td class="article_column second_column" width="50%" valign="top">
<div class="contentpaneopen-tomsroundedcategory">
</div>
<div class="contentpaneopen-tomsroundedcategory">
</div>
<div class="contentpaneopen-tomsroundedcategory">
</div>

</td>
</tr>
</tbody>


So there is the outer wrapper table (width100%) and then a cell for the left-hand column (td class="article_column" width 50%). Inside that cell are all the articles. Then there is the right-hand column (td class="article_column second_column" width="50%") which houses all the right hand columns.

I am hopless with PHP, and I need to know -

Will changing the columns from tables to divs require any alteration of my Joomla/php code to display the 2 columns? Im asking becuase the php/joomla code outputs as html eg sets up the table columns.

I have tried to create a 2-colum layout using DIVS for the page, but I dont know how to code the php to get the articles to display in both of the two columns using Divs, and I havent had any luck on the Joomla forum either.

The php/joomla code for the default.php file is -


<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<?php if ($this->params->get('show_page_title', 1)) : ?>
<div class="componentheading<?php echo $this->params->get('pageclass_sfx') ?>">
<?php echo $this->escape($this->params->get('page_title')); ?>
</div>
<?php endif; ?>

<?php if ($this->params->def('num_leading_articles', 1)) : ?>

<?php else : $i = $this->pagination->limitstart; endif;
?>


<?php
$startIntroArticles = $this->pagination->limitstart + $this->params->get('num_leading_articles');
$numIntroArticles = $startIntroArticles + $this->params->get('num_intro_articles', 4);
if (($numIntroArticles != $startIntroArticles) && ($i < $this->total)) :
?>


<table width="100%"><?php $divider = ''; if ($this->params->def('multi_column_order',1)) :
$i = $i + $this->params->get('num_intro_articles') ;
else :
for ($z = 0; $z < $this->params->get('num_columns'); $z ++) :
if ($z > 0) : $divider = " second_column"; endif;
?>

<td valign="top" width="<?php echo intval(100 / $this->params->get('num_columns')) ?>%" class="article_column<?php echo $divider ?>">
<?php for ($y = 0; $y < ($this->params->get('num_intro_articles') / $this->params->get('num_columns')); $y ++) :
if ($i < $this->total && $i < ($numIntroArticles)) :
$this->item =& $this->getItem($i, $this->params);
echo $this->loadTemplate('item');
$i ++;
endif;
endfor;
?>

</td>
<?php endfor;
endif;?>
</table>

<?php endif; ?>


Can anyone help me with the php code as Im useless with php.

moss2076
03-18-2009, 07:50 PM
Can anyone help me out?:confused:

steelaz
03-18-2009, 08:33 PM
Try replacing this code:



<table width="100%"><?php $divider = ''; if ($this->params->def('multi_column_order',1)) :
$i = $i + $this->params->get('num_intro_articles') ;
else :
for ($z = 0; $z < $this->params->get('num_columns'); $z ++) :
if ($z > 0) : $divider = " second_column"; endif;
?>

<td valign="top" width="<?php echo intval(100 / $this->params->get('num_columns')) ?>%" class="article_column<?php echo $divider ?>">
<?php for ($y = 0; $y < ($this->params->get('num_intro_articles') / $this->params->get('num_columns')); $y ++) :
if ($i < $this->total && $i < ($numIntroArticles)) :
$this->item =& $this->getItem($i, $this->params);
echo $this->loadTemplate('item');
$i ++;
endif;
endfor;
?>

</td>
<?php endfor;
endif;?>
</table>



With this one:



<div style="width: 100%; overflow: hidden;"><?php $divider = ''; if ($this->params->def('multi_column_order',1)) :
$i = $i + $this->params->get('num_intro_articles') ;
else :
for ($z = 0; $z < $this->params->get('num_columns'); $z ++) :
$float_direction = if ($z > 0) ? 'right' : 'left';
$column_width = intval(100 / $this->params->get('num_columns'));
?>

<div style="width:<?= $column_width ?>%; float:<?= $float_direction ?>">
<?php for ($y = 0; $y < ($this->params->get('num_intro_articles') / $this->params->get('num_columns')); $y ++) :
if ($i < $this->total && $i < ($numIntroArticles)) :
$this->item =& $this->getItem($i, $this->params);
echo $this->loadTemplate('item');
$i ++;
endif;
endfor;
?>

</div>
<?php endfor;
endif;?>
</div>

moss2076
03-18-2009, 09:08 PM
Thankyou for replying, im pulling my hair out - seriously!

I replaced the table section of code with your code, but get a php generated error message. Im sorry my php isnt good enough to even begin working it out -

Parse error: syntax error, unexpected T_IF in E:\domains\t\tomsspecialreserve.co.uk\user\htdocs\joomla\templates\toms_joomla_test\html\com_content \frontpage\default.php on line 26

Line 26 of my article.php is
$float_direction = if ($z > 0) ? 'right' : 'left';.

steelaz
03-18-2009, 09:18 PM
My bad, this line should be:


$float_direction = ($z > 0) ? 'right' : 'left';

moss2076
03-18-2009, 09:23 PM
That has sorted it!!

Have a look if you want - http://www.tomsspecialreserve.co.uk/joomla

Can I be really pushy and ask if it is actually possible to name the wrapper div, and the left and right column divs eg name them div id="PrimaryColumn", div id="SecondaryColumn", and place their width settings in a CSS file instead of in the markup, or am I is that not an option becuase of the php code?

I wish I could learn php, but it just doesnt sink in for me.

steelaz
03-18-2009, 09:42 PM
No problem, just don't forget that "Thank you" button :thumbsup:



<div class="PrimaryColumn">
<?
if ($this->params->def('multi_column_order',1)):
$i = $i + $this->params->get('num_intro_articles');
else:
for ($z = 0; $z < $this->params->get('num_columns'); $z ++) :
$column_class = if ($z > 0) ? 'RightColumn' : 'LeftColumn';

echo '<div class="'.$column_class.'">';

for ($y = 0; $y < ($this->params->get('num_intro_articles') / $this->params->get('num_columns')); $y ++) :
if ($i < $this->total && $i < ($numIntroArticles)) :
$this->item =& $this->getItem($i, $this->params);
echo $this->loadTemplate('item');
$i ++;
endif;
endfor;

echo '</div>';

endfor;
endif;
?>
</div>


Now you have wrapper div as "PrimaryColumn", then "LeftColumn" and "RightColumn".

moss2076
03-18-2009, 10:59 PM
:thumbsup:
You are a true genius! I wish I knew what you knew, thankyou so much.

I will start a new thread tomorrow as I need to work out why my leading articles at the top of the frontpage wont display, but getting the columns to display with divs/css is more than enough for one day :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum