skip to Main Content

I have created this from advanced custom fields and would like to display a restaurant menu in rows and column. The first three columns are displaying as intended but for unknown reason the last column does not display within the table. As shown on the attached image, the last column is showing above the table header and I am not sure what’s wrong with the code.

[Screenshot of the frontend display1

`

    <table>
    <thead>
        <tr>
          <td class="photo">Photo</td>
            <td class="menu_name">Menu Item</td>
            <td class="descriptions">Descriptions</td>
            <td class="price">Price</td>
          </tr>
        </thead> 
    <?php while ( have_rows( 'restaurant_menu_items' ) ) : the_row(); ?>
    
    <tr>
    
        <td><?php $photo = get_sub_field( 'photo' ); ?>
        <?php $size = 'thumbnail'; ?>
        <?php if ( $photo ) : ?>
            <?php echo wp_get_attachment_image( $photo, $size ); ?>
        <?php endif; ?> </td>
        
        <td> <?php the_sub_field( 'menu_name' ); ?></td>
        
        <td><?php the_sub_field( 'descriptions' ); ?></td>
        
        </td><?php the_sub_field( 'price' ); ?></td>
        
    <?php endwhile; ?>
    </tr>
</table>
<?php else : ?>
    <?php // no rows found ?>
    
<?php endif; ?>`

2

Answers


  1. you have typo error on the opening tag of the last td

    **</td>**<?php the_sub_field( 'price' ); ?></td>
    

    should be < td > without /

    Hope it works! 🙂

    Login or Signup to reply.
  2. Also, the tr tag is opening in while loop. So it should close in the while loop. Please check below code:

    <?php while ( have_rows( 'restaurant_menu_items' ) ) : the_row(); ?>
    
    <tr>
    
        <td><?php $photo = get_sub_field( 'photo' ); ?>
        <?php $size = 'thumbnail'; ?>
        <?php if ( $photo ) : ?>
            <?php echo wp_get_attachment_image( $photo, $size ); ?>
        <?php endif; ?> </td>
        
        <td> <?php the_sub_field( 'menu_name' ); ?></td>
        
        <td><?php the_sub_field( 'descriptions' ); ?></td>
        
        <td><?php the_sub_field( 'price' ); ?></td>
      </tr>
    <?php endwhile; ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search