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

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

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

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

Categories: