Return 单人发帖 table

Return Posts as single table

query_posts( array(
'post_type' => 'ts_result',
'meta_query' => array(
    array(
       'key' => '_ts_student_class',
       'value' => $exam_reg,
       'compare' => '='
    ),
    array(
       'key' => '_ts_school_term',
       'value' => $exam_term,
    ),
    array(
       'key' => '_ts_school_year',
       'value' => $exam_year,
    )
),
'posts_per_page' => 100
   )
);
?>

<table style="border:1px solid black" cellpadding="1.5" cellspacing="5">
<style type="text/css" media="print">

table{
    border-collapse:collapse;
}
</style>
<tbody>

<tr>
    <th><strong>NAME\SUBJECT</strong></th>
    <th><strong>English Studies</strong></th>
    <th align='center'><strong>Mathematics</strong></th>
    <th align='center'><strong>CCA</strong></th>
    <th align='center'><strong>Yoruba Language</strong></th>
    <th align='center'><strong>French</strong></th>
    <th align='center'><strong>Business Education</strong></th>
    </tr>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php 
     $subject_english_studies_exam_total= get_post_meta( 
     get_the_ID(),'_ts_subject_english_studies_exam_total',true );
       $subject_maths_exam_total= get_post_meta( 
     get_the_ID(),'_ts_subject_maths_exam_total',true );
      $subject_creative_arts_exam_total= get_post_meta( 
     get_the_ID(),'_ts_subject_creative_arts_exam_total',true );
     $subject_yoruba_lang_exam_total= get_post_meta( 
     get_the_ID(),'_ts_subject_yoruba_lang_exam_total',true );
     $subject_french_exam_total= get_post_meta( 
     get_the_ID(),'_ts_subject_french_exam_total',true );
       $subject_business_edu_exam_total= get_post_meta( 
     get_the_ID(),'_ts_subject_business_edu_exam_total',true );
?> 

<tr>
    <td><?php the_title(); ?></td>
    <td><?php echo $subject_english_studies_exam_total ;?></td>
    <td><?php echo $subject_maths_exam_total ;?></td>
    <td><?php echo $subject_creative_arts_exam_total ;?></td>
    <td><?php echo $subject_yoruba_lang_exam_total ;?></td>
    <td><?php echo $subject_french_exam_total ;?></td>
    <td><?php echo $subject_business_edu_exam_total ;?></td>
   </tr>
</tbody>
</table>

在 Wordpress 中的上述查询 returns 以下内容:

我想要实现的是一个 table,其中一个 header 和另一个 post 内容作为行。目前只有前 post 个值被正确格式化为 table 行。

你犯了一个小错误,没有在 </tbody> 之前关闭 while 循环。代码将如下所示:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  <tr>
   <td><?php the_title(); ?></td>
   <td><?php echo $subject_english_studies_exam_total ;?></td>
   <td><?php echo $subject_maths_exam_total ;?></td>
   <td><?php echo $subject_creative_arts_exam_total ;?></td>
   <td><?php echo $subject_yoruba_lang_exam_total ;?></td>
   <td><?php echo $subject_french_exam_total ;?></td>
   <td><?php echo $subject_business_edu_exam_total ;?></td>
 </tr>
<?php endwhile;endif; ?>

希望对你有帮助。