2017-04-24 15 views
0
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の中に上記のクエリは、次の値を返します。私が達成しようと何戻る投稿

Screenshot of output

1つのヘッダと行など、他のポストコンテンツを持つテーブルです。現在のところ、最初のポスト値だけがテーブル行として適切にフォーマットされています。

答えて

1

</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; ?> 

希望します。

+0

[私にとってはこの問題があります](https://stackoverflow.com/questions/44212837/calculate-position-rank-for-returned-post) –

関連する問題