2

注意:我已经编辑了下面的代码以反映现在可以使用的方式,感谢您的帮助!

我的查询从我的自定义帖子和自定义字段中提取了我要求的所有数据。字段填写,行和列看起来不错。但是 css 表正在破坏,以至于(正如 Nathan 在下面指出的那样)每个帖子都显示在一个单独的表中,我在一行上得到一个标题,在一行上得到一个标题,等等。

我尝试了多种方法来对表格进行编码,但每次显示的行都完全一样。

我承认,这很混乱,但我没有在表结构上采取任何捷径,以便准确显示我得到它的方式,至少在正确的列中显示所有数据

<?php
 $querystr = "
    SELECT $wpdb->posts.* 
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
    AND $wpdb->posts.post_status = 'publish' 
    AND $wpdb->posts.post_type = 'event'
    AND $wpdb->posts.post_date < NOW()
    ORDER BY $wpdb->posts.post_date DESC
 ";

 $pageposts = $wpdb->get_results($querystr, OBJECT_K);

 ?>
 <div class="post" id="post-<?php the_ID(); ?>">
   <?php if ($pageposts): ?>
 <?php global $post; ?>
<table class="maee-table"><col width="20%"><col width="30%"><col width="20%"><col width="30%">
<tr><th class="column-head">Date</th>
<th class="column-head">Name</th>
<th class="column-head"> Audience</th>
<th class="column-head">Submitting partner</th>
</tr>
 <?php foreach ($pageposts as $post): ?>
 <?php setup_postdata($post); ?>

   <tr>
     <td class="maee-row"><?php rwmb_the_value( 'prefix-event_date1');?></td> 
 <td class="maee-row"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></td>
      <td class="maee-row" ><?php rwmb_the_value( 'prefix-event_audience1');?></td>
<td class="maee-row"> <?php the_category(', ') ?></td>
   </tr>
  <?php endforeach; ?>
  </table>
 </div>
 <?php endif; ?>
</section>
4

1 回答 1

0

你可以尝试这样的事情:

    global $wpdb;

    $querystr = "
    SELECT $wpdb->posts.* 
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
    AND $wpdb->posts.post_status = 'publish' 
    AND $wpdb->posts.post_type = 'event'
    AND $wpdb->posts.post_date < NOW()
    ORDER BY $wpdb->posts.post_date DESC
 ";



    $content = '<table class="maee-table"><col width="20%"><col width="30%"> 
<col width="20%"><col width="30%">';

    $content .= '<tr><th>Date</th><th>Name</th><th>Audience</th><th>Submitting Partner</th></tr>';

    $results = $wpdb->get_results($querystr);

    global $post; // left this out before.  Try this.    

    foreach ($results as $post) {

        setup_postdata($post);

        $content .= '<tr>';
        $content .= '<td class="maee-row">' . rwmb_the_value( 'prefix- 
event_date1') . '</td>';
        $content .= '<td class="maee-row">' . the_title() . '</td>';
        $content .= '<td class="maee-row">' . rwmb_the_value( 'prefix- 
event_audience1') . '</td>';
        $content .= '<td class="maee-row">' . the_category(', ') . '</td>';
        $content .= '</tr>';
    }
    $content .= '</table>';

    // return the table
    echo $content;
于 2019-08-10T17:55:19.937 回答