ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

{Switch} switching, then not, then switching again - random display

August 05, 2007 8:32am

Subscribe [1]
  • #1 / Aug 05, 2007 8:32am

    Gizmo

    5 posts

    Hi all,

    I am having a few issues with {switch}. I know why it’s doing what it’s doing (I think!), but I’m not sure how to get around it.

    At the moment I am ordering my weblog by date, and using an {if} statement to only show entries where a custom field = “Team A”
    Then displaying using the following code:

    <table cellspacing="0" cellpadding="0">
        <tr>
            <th>Date</th>
            <th>Home</th>
            <th>Score</th>
            <th>Away</th>
            <th>Competition</th>
            <th>Time</th>
            <th>Venue</th>
            <th>Report</th>
        </tr>
    
        {exp:weblog:entries  weblog="{my_weblog}"  orderby="date" sort="asc" show_future_entries="yes"}
        {if match_hometeam=="Team A" OR match_awayteam=="Team A"}
        <tr class="{switch="|alt"}">
            <td>{entry_date format="%j/%n/%Y"}</td>
            <td><a href="http://site/matchreports/Team">Report</a></td>
        </tr>
        {/if}
        {/exp:weblog:entries}
    
    </table>

    So one <td> with a “alt” class, and the other without. Problem is, the colours don’t alternate. They appear random. I think this is because it is applying the switch to ALL the entries in the date-sorted order, then pulling the entries which match my conditional. If these happen to be the same ‘switch’, then the two rows will be the same colour.

    Any thoughts?

    cheers
    Gizmo

  • #2 / Aug 05, 2007 12:01pm

    Gizmo

    5 posts

    Actually, on a similar issue I am trying to display the next 5 matches for Team A on my index page.

    As a rough idea of what I have in my weblog so far:

    Date      Home Team        Away Team
    15/8      Team A           Team C
    16/8      Team C           Team D
    17/8      Team C           Team A
    18/8      Team B           Team A
    19/8      Team A           Team B
    20/8      Team F           Team A

    and using:

    {exp:weblog:entries weblog="match" limit="5" sort="asc" show_future_entries="yes" start_on="<?php echo $current_time; ?>" rdf="off" dynamic="off"}
    
    {if match_hometeam=="Team A" OR match_awayteam=="Team A"}
    display the info…

    even though limit=5 it will not return that last match (F vs A) as it has already counted 5, and discounted the C vs D.
    How can I get it to cycle through only the entries that have matched the custom field criteria? I.e. to display the next 5 that have Team A in them?

    Will it involve a query as I think it might? If so, would someone be able to point me in the right direction in terms of what fields etc I would need, and how, if at all, it interacts with the weblog entries tag?

    Thanks in advance

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases