0

I'm trying to create a plugin, and want to show up a table, in which WP posts would be shown. I can do it with the following code:

echo '<table class="custom_type_table">';

$custom_type_args = array(
   'post_type' => 'custom_type',
   'posts_per_page' => '-1',
);

$query = new WP_query ( $custom_type_args );

if ( $query->have_posts() ) {

$i = 0;
while ( $query->have_posts() ) : $query->the_post();
   // Functions
?>
<?php if($i == 0){ echo '<tr class="custom_type_row">'; }?>

   <td class="custom_type_cell" width="33.3%">
      // Some content here
   </td>

<?php $i++;?>
<?php if($i == 3){echo "</tr>"; $i = 0;}?>

<?php endwhile;
   if($i == 3) echo '</tr>';
}

echo '</table>';

The case is, I want to add an empty cell in the row with three cells if at least one of them is empty. Something like this:

<table class="custom_type_table">
   <tr class="custom_type_row">
       <td class="custom_type_cell" width="33.3%">
           // Some content
       </td>
       <td class="custom_type_cell" width="33.3%">
           // Some content
       </td>
       <td class="custom_type_cell" width="33.3%">
           // Some content
       </td>
   </tr>

    <tr class="custom_type_row">
       <td class="custom_type_cell" width="33.3%">
           // Some content
       </td>
       <td class="custom_type_cell" width="33.3%">
          // EMPTY CELL
       </td>
       <td class="custom_type_cell" width="33.3%">
          // EMPTY CELL
       </td>
    </tr>
</table>

I tried to change the first code in different ways, but nothing worked. Could you give me some easy example of how to do that? I would really appreciate any help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.