x
 
Create New Page
 View Previous Changes    ( Last updated by Mark Bowen )

Entries In Table

Question:

I intend to create a template that displays entry titles in a table consisting of four columns and x number of rows. Anyone know have an example of the most effective way to achieve this?

Answer:

<table><tr
{exp:weblog:entries orderby="date" sort="desc" limit="20" weblog="{master_weblog_name}" cache="yes" refresh="60" disable="categories|custom_fields|member_data|trackbacks"
<td>{count} {title}</td
{if count == "4"}</tr><tr>{/if} 
{if count 
== "8"}</tr><tr>{/if} 
{if count 
== "12"}</tr><tr>{/if} 
{if count 
== "16"}</tr><tr>{/if} 
{
/exp:weblog:entries} 
</tr></table

Thread

Alternate Option

Edited by Mark Bowen - Wednesday 10th June 2009 - 11:00PM

It would be possible to do this using some creativity with the switch= parameter, as that can take unlimited parameters.

<table>
{exp:weblog:entries weblog="default_site"}
{switch
="<tr>|||"}
<td>{count} {title}</td>
{switch="|||</tr>"}
{
/exp:weblog:entries}
</table

This is not always as easy to tell exactly what is going on but for simple cases can be quite powerful. I also believe that this will not give you any empty <tr> tags if you don’t have say 16 entries as per the example above.
End of Edit

 

PHP Option

If you turn PHP parsing on for your template (output), you can output your entries in columns in the following way (the example showing 3 column output):

{exp:weblog:entries weblog="weblog" orderby="title" sort="asc"}
{if count 
=="1"}
<table>
{/if}
<?php
$columns 
3;
$i{count}-1;
 if(
$i $columns == 0{
   
echo "<tr>\n"//if there is no remainder, start new row
 
}
?>
<td>{count}{title}</td>
<?php
 
if(($i $columns) == ($columns 1) || ($i 1) == {total_results}{
   
//if there is a remainder of 1 or no results left, end the row
    
echo "</tr>\n";
 
}
?>
{if count 
== total_results}
</table>
{/if}
{
/exp:weblog:entries} 

Category:Entries Category:Templates

Category:EE1

Categories: