How to show art from category in two columns ?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: May 12, 2010   (RSS)

By esteban - May 10, 2010

I would like to show this in two column and show name of category.

<?php header('Content-type: text/html; charset=utf-8'); ?>

<?php

require_once "/home/trener_osobisty/trener_osobisty/cmsAdmin/lib/viewer_functions.php";

list($artykulyRecords, $artykulyMetaData) = getRecords(array(
'tableName' => 'artykuly',
'limit' => '4',
'where' => 'on_index',
));

?>


-----------------------------------

This code show my 4 article, and I need to show this 4 article i two column and add a category name from which an article comes in this place: <!-- Here I need put Category name -->

<table width="233" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="233">

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<?php foreach ($artykulyRecords as $record): ?>

<!-- STEP 2a: Display Uploads for field 'zdjecie_glowne' -->
<?php foreach ($record['zdjecie_glowne'] as $upload): ?>

<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $record['_link'] ?>">
<img src="<?php echo $upload['thumbUrlPath2'] ?>" alt="<?php echo $record['title'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" border="0" align="left" class="foto-ramka" /></a>
<?php endif ?>
<?php endforeach ?><br />

</td>
</tr>
<tr>
<td><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a><br/>
Zajawka: <?php echo $record['zajawka'] ?><br/>

<!-- Here I need put Category name -->

<p class="dot_hor">&nbsp;</p>

<?php endforeach ?>

<?php if (!$artykulyRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records --></td>
</tr>
</table>

-------------------------------------

For category:

<?php

require_once "/home/trener_osobisty/trener_osobisty/cmsAdmin/lib/viewer_functions.php";

list($main_menuRecords, $main_menuMetaData) = getRecords(array(
'tableName' => 'main_menu',
));

?>

Every article has a category = "category_num" but every category_num has a name = "name" and I need put this name.

----------------

This is this website: http://goo.gl/QTno

Please help Interactivetools.

Re: [esteban] How to show art from category in two columns ?

By gkornbluth - May 11, 2010 - edited: May 11, 2010

Hi esteban,

Limiting the amount of columns is not too difficult. Here's an excerpt from my CMSB Cookbook http://www.thecmesbcookbook.com that describes an approach:

LIMITING THE AMOUNT OF COLUMNS IN A SINGLE ROW IMAGE DISPLAY

Here’s a suggestion from Dave:

The CSS way is to have each image in a div that has something like: style="float: left; width: 200px". This will make them flow from left to right and wrap when they run out of space (you can put them inside a bigger fixed width container).

Or with a table you can have one table cell per image and insert a closing and opening TR every X images. Here's a code snippet that does that:

<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>

Which is just a way of saying "Every 2 images insert "</tr><tr>"".

Here’s a single row example using the thumbnail2 image as a link to a detail page, separate Title and Subtitle fields, a hidden border for IE and a fixed height for the image cell so that everything lines up nicely.

<table width="100%" border="0" cellpadding="5">
<tr>
<?php foreach ($your_sectionRecords as $record): ?><?php foreach ($record['image'] as $upload): ?>
<td align=”center” height="350" valign="bottom">
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" style="border:hidden" /><br /><div align="center" class="medium-title"><?php echo $record['title'] ?></div>
<div align="center" class="medium-text"><?php echo $record['sub_title'] ?></div></a>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?><?php endforeach ?>
</tr>
</table>


Similarly, if you’re not using images this code will output a </tr><tr> after every 2 <td>...your content...</td> lines:

<table border="1">
<tr>

<?PHP foreach ($yourrecords as $record): ?>
<td>
<?PHP echo $record['your_content'] ?><br/>
</td>
<?PHP $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?PHP endif; ?>
<?PHP endforeach; ?>
</tr>
</table>


Use your own variable names instead of $yourrecord, but the line in red can stay the same.

Hope that gets you going.

CATEGORIES
There are a number of ways to show a category. Where does the category name come from? A list field? Some other way?

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] How to show art from category in two columns ?

By esteban - May 11, 2010

Sorry I don't understand, I do not know PHP and I just can not pass on it in your example. You Give me a solution for images and content separately and I have this one and there are twice as <? Php endforeach?>. What to do in this situation?

Re: [esteban] How to show art from category in two columns ?

By esteban - May 11, 2010 - edited: May 11, 2010

Ok I figured out. Working :-) Your post was helpfull. Thanks.