entries displayed as html table
Posted: 03 November 2005 12:46 PM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  187
Joined  09-14-2005

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?

{exp:weblog:entries weblog="news" limit="15"}

<td>{title}</td>

{/exp:weblog:entries}

Basically, I just need to throw a “</tr><tr>” after every four entries.

Will I need to put some PHP in the template, or can this be done within EE somehow?

 Signature 

Chris Shontz
Official Tech Support Nuisance
Chris’s Flickr Photos

Profile
 
 
Posted: 03 November 2005 12:51 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33269
Joined  05-14-2004

The only way that I can think of to do this natively would be to use 4 instances of {exp:weblog:entries}, using offsets to get the right things into the right row.

Just out of curiosity, though, did you want:

Entry 1 entry 2 entry 3 entry 4
entry 5 entry 6 entry 7 entry 8
Etc

Or

Entry 1 entry 5
Entry 2 entry 6
Entry 3 entry 7
Entry 4 entry 8
etc

?

 Signature 
Profile
MSG
 
 
Posted: 03 November 2005 01:07 PM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23744
Joined  05-20-2002

Mm- could probably use a little php-

<?php
if ({count} % 4 == 0)  { echo '</tr><tr>';  }
?>


PHP parsed on output.  If it treats count as numeric, should work.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 03 November 2005 01:12 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33269
Joined  05-14-2004

Ugh, I keep forgetting that the count variable was added.  I bet you could do this, using that, without PHP…  Same theory as the PHP but using {count}?

{if count == "4"}<tr>{/if}
{if count
== "4"} </tr><tr>{/if}
{if count
== "8"}</tr><tr>{/if}
{if count
== "16"}</tr>

I have a feeling something with this is a bit off.  The problem is needing to do this 3 times, you might need to encapsulate the custom fields in it, too… so rob1’s code may be better to use for this.

 Signature 
Profile
MSG
 
 
Posted: 03 November 2005 01:13 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
RankRank
Total Posts:  187
Joined  09-14-2005

Is EE capable of simple math operations per chance?

All I’d need would be something like this:

{if count MOD 4 = 0}
</tr><tr>
{/if}

Man, that’d be sweet! :D

To answer your question, Lisa - I wish to present the entries as such:

01 02 03 04
05 06 07 08
etc

 Signature 

Chris Shontz
Official Tech Support Nuisance
Chris’s Flickr Photos

Profile
 
 
Posted: 03 November 2005 01:15 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33269
Joined  05-14-2004

You can use ==, less than and greater than, but no maths.  There is a list of operators in global conditional variables.

 Signature 
Profile
MSG
 
 
Posted: 03 November 2005 01:18 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
RankRank
Total Posts:  187
Joined  09-14-2005
Lisa - 03 November 2005 01:15 PM

You can use ==, less than and greater than, but no maths.  There is a list of operators in global conditional variables.

Oh well - it was wishful thinking. In any case, you guys totally answered my question. I’ll just drop in some PHP. I just like to rule out every other option before I monkey with PHP. Thanks for your help! smile

 Signature 

Chris Shontz
Official Tech Support Nuisance
Chris’s Flickr Photos

Profile
 
 
Posted: 03 November 2005 01:28 PM   [ Ignore ]   [ # 7 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23744
Joined  05-20-2002

I thought for a moment it would fit in an EE conditional as well, but it doesn’t look like it.  Would make a cool feature request!

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 03 November 2005 03:06 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  187
Joined  09-14-2005

After realizing that the {count} value isn’t cumulative, and it starts counting anew with each page, I decided that Lisa’s suggestion was perfectly reasonable considering I was limiting each page to twenty entries. Here’s what it looks like, and it works like a charm.

{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}

Although I would’ve liked to condense the count condition to something like this {if count == “4|8|12|16”}{/if}, but that didn’t fly. That’s just me nit-picking. smile

If the count value was a cumulative representation of all of the entries, I would’ve needed to perform that modulus operation via PHP as described above by Robin.

Thanks for your help, Jill and Robin. I owe you beers.

 Signature 

Chris Shontz
Official Tech Support Nuisance
Chris’s Flickr Photos

Profile
 
 
Posted: 03 November 2005 03:49 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  144
Joined  06-19-2005

Thanks cshontz, Lisa, rob1 for this coce.
I’ll try it out.
Great place here. smile

Profile
 
 
Posted: 03 November 2005 05:24 PM   [ Ignore ]   [ # 10 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33269
Joined  05-14-2004

Wiki’d.  If someone wants to make the question more generic, go ahead.  I was having trouble re-phrasing it. =)

 Signature 
Profile
MSG
 
 
Posted: 19 August 2007 10:32 AM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1839
Joined  03-26-2006

I just wanted to let people know I made my first update to the Wiki (on ANY subject) about this - I added a PHP solution, which I suppose I might as well put here as well.

Link to Wiki Article for using PHP to display results in columns

This example shows 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}

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66392 Total Logged-in Users: 24
Total Topics: 84721 Total Anonymous Users: 15
Total Replies: 454707 Total Guests: 195
Total Posts: 539428    
Members ( View Memberlist )