Support

Account

Forum Replies Created

  • Quite right, thanks for having a look at the code for me.

    I modified it to use traditional syntax : rather than {} and added the endforeach but it was still limiting to current month only.

    I modified the loop to output month and one entry, and then kept the else statement the same. It not outputs month name, and all entries in chronological order. I’m not 100% sure this is the best way to achieve this, but it appears to work on the front end and doesn’t throw and php errors on the back end.
    Code:

    	    <?php
                 
                 $repeater = get_field('races');
                 foreach( $repeater as $key => $row ) :
                   
                     $column_id[ $key ] = $row['race_date'];
                   endforeach; 
                   array_multisort( $column_id, SORT_ASC, $repeater );
                   
    	       $currMonth = "start";
    	       foreach( $repeater as $row ) :
    	       
    		
    		    $date = DateTime::createFromFormat('Ymd', $row['race_date']);
    			
    			if ($currMonth != $date->format('F')) 
    				    :
    				    echo '<tr class="month"><td><h2>' . $date->format('F') . '</h2></td></tr><br>';
    				    $currMonth = $date->format('F');
    				    echo '<tr class="race">';
    				
    				       echo '<td class="cell">' . $date->format('m/d') . '</td>';
    				       echo '<td class="cell"><h2>' . $row['race_name'] . '</h2></td>';
    				       echo '<td class="cell">' . $row['race_location'] . '</td>';
    				       echo '<td class="cell">' . $row['race_gender'] . '</td>';
    			echo '</tr>';
    				    
    			else : 
    			
    			echo '<tr class="race">';
    				
    				       echo '<td class="cell">' . $date->format('m/d') . '</td>';
    				       echo '<td class="cell"><h2>' . $row['race_name'] . '</h2></td>';
    				       echo '<td class="cell">' . $row['race_location'] . '</td>';
    				       echo '<td class="cell">' . $row['race_gender'] . '</td>';
    			echo '</tr>';
    			
    			endif;
    			
    
    		endforeach; 
                   ?>
    

    Thanks for starting this thread, super helpful!

  • I’m getting closer, I think. I’ve gotten the month names to create their own rows and cells within the table in the proper order, but now the code is limiting the results on the table to entries in the current month (February).

    What I’m trying to do is echo month name on its own row before array entries for that month, and if it is not the start of a new month, echo the entries in the array in individual TD elements.

    Any thoughts would be helpful, I think I’m just not good enough with PHP to figure this one out alone.

    
    	<table id="race-calendar">
    	    <thead>
    		<tr>
    		   <th>Date</th>
    		   <th>Race Name</th>
    		   <th>Location</th>
    		   <th>Men's/Women's/Both</th>
    		</tr>
    	    </thead>
    	    <?php
                 
                 $repeater = get_field('races');
                 foreach( $repeater as $key => $row )
                   { 
                     $column_id[ $key ] = $row['race_date'];
                   } 
                   array_multisort( $column_id, SORT_ASC, $repeater );
                   
    	       $currMonth = "start";
    	       foreach( $repeater as $row )
    	       
    		{
    		    $date = DateTime::createFromFormat('Ymd', $row['race_date']);
    			
    			if ($currMonth != $date->format('F')) 
    				    {
    				    echo '<tr><td colspan="2"><h2>' . $date->format('F') . '</h2></td></tr><br>';
    				    $currMonth = $date->format('F');
    				    }
    			else { 
    			echo '<tr class="race">';
    				
    				       echo '<td class="cell">' . $date->format('m/d') . '</td>';
    				       echo '<td class="cell"><h2>' . $row['race_name'] . '</h2></td>';
    				       echo '<td class="cell">' . $row['race_location'] . '</td>';
    				       echo '<td class="cell">' . $row['race_gender'] . '</td>';
    			echo '</tr>';
    			
    			}
    			
    
    		}
                   ?>
    	</table>
    

    Thanks!

  • I can’t believe that this thread exists – this is exactly what I was working on and nearly gave up after a few hours of trying to figure it out. So, I have a really stupid basic question on this front, now that I’ve got my race calendar working (seriously, was actually working on a race calendar too):

    When working with an UL / LI structure it injects the month name into the proper sorted location – is this possible with a table structure? I can’t get the month names to insert themselves, they end up creating their own TR elements outside of the sorted elements.

    Thanks for this! Fabulous

Viewing 3 posts - 1 through 3 (of 3 total)