【问题标题】:Bootstrap table doubles/triples etc the rows引导表加倍/三倍等行
【发布时间】:2020-08-04 18:17:40
【问题描述】:

我有一个问题(我正在使用带有我自己代码的 WordPress)。 在实现引导表对我的数据进行排序之前,它显示了 3 行信息,在实现之后显示了 9 行,所以我尝试再添加一个帖子,结果显示为 16(每次翻倍)。 我应该在我的代码中进行哪些更改以停止乘法? 使用过滤器后,我从 url 获取数据到表中(从 wordpress 帖子中搜索)

    <div class="table-responsive">
            <table 
 id="table"
data-toggle="table"
  data-search="true"
  data-show-columns="true"
 class="table table-striped">
      <thead>
        <tr>
          <th  scope="col">Goods</th>
          <th  scope="col">Tent</th>
          <th   data-sortable="true" scope="col">Load/Unload</th>
          <th   scope="col">From/To</th>
        </tr>
      </thead>
                <div class="post clearfix">
            <?php
                    $args = array(
                        'post_type' => 'post',
                        'posts_per_page' => -1,
                        'meta_query' => array(
                            array(
                                'key' => 'tent',
                                'value' => $tent,
                                'compare' => 'LIKE'
                            ),

                            array(
                                'key' => 'laadimise_kp',
                                'value' => array($laadimise_kp, $mahalaadimine),
                                'compare' => 'BETWEEN',
                                'type' => 'DATE'
                            ),

                            array(
                                'key' => 'from',
                                'value' => $from,
                                'compare' => 'LIKE'
                            ),

                            array(
                                'key' => 'to',
                                'value' => $to,
                                'compare' => 'LIKE'
                            ),
                        )
                    );
                    $query = new WP_Query($args);
                    while($query -> have_posts()) : $query -> the_post();
            ?>
            </div>


      <tbody>
          <th ><?php the_title( '<h5 style="font-size: 16px;" class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h5>' ); ?></th>
          <td ><?php the_field('tent'); ?></td>
          <td ><?php the_field('laadimise_kp'); ?> <strong>-</strong>  <?php the_field('mahalaadimine'); ?><br></td>
          <td ><?php the_field('from'); ?><strong>-</strong><?php the_field('to'); ?></td> 
      </tbody>


            <?php endwhile; wp_reset_query(); ?>

    </table></div>

图片: How it should look likeHow it looks

【问题讨论】:

    标签: html wordpress bootstrap-4 bootstrap-table


    【解决方案1】:

    我不擅长使用 WP,但是您的 HTML 标记需要更改,因为您直接在表格中添加 DIV 元素,这是不行的,并且您正在使用 WHILE 循环并为每个循环重复 TBODY 元素。

    表结构是这样的:

    <table>
        <thead>
            <tr><th>Col Heading</th></tr>
        </thead>
        <tbody>
            <tr><td>Cell Value1</td></tr>
            <tr><td>Cell Value2</td></tr>
        </tbody>
        <tfoot>
            <tr><th>Col Heading</th></tr>
        </tfoot>
    </table>
    

    您需要重新格式化您的代码和结构,使其与此类似。

    【讨论】:

    • 如果我在 TBODY 中使用 while 循环,那么表格就会完全混乱 图片:imgur.com/a/1vHJLwh
    【解决方案2】:

    在标题和正文中只添加了一个后,我让它工作了

        <div class="post clearfix">
                    <div class="table-responsive">
                <table 
         data-toggle="table"
      data-search="true"
      data-show-columns="true"
     class="table table-striped">
          <thead>
            <tr>
              <th  scope="col">Goods</th>
             <th  scope="col">Tent</th>
             <th   data-sortable="true" scope="col">Load/Unload</th>
            <th   scope="col">From/To</th>
          </tr>
    
          </thead>
    
    
    
          <tbody>
    <?php
                        $args = array(
                            'post_type' => 'post',
                            'posts_per_page' => -1,
                            'meta_query' => array(
                                array(
                                    'key' => 'tent',
                                    'value' => $tent,
                                    'compare' => 'LIKE'
                                ),
    
                                array(
                                    'key' => 'laadimise_kp',
                                    'value' => array($laadimise_kp, $mahalaadimine),
                                    'compare' => 'BETWEEN',
                                    'type' => 'DATE'
                                ),
    
                                array(
                                    'key' => 'from',
                                    'value' => $from,
                                    'compare' => 'LIKE'
                                ),
    
                                array(
                                    'key' => 'to',
                                    'value' => $to,
                                    'compare' => 'LIKE'
                                ),
                            )
                        );
                        $query = new WP_Query($args);
                        while($query -> have_posts()) : $query -> the_post();
    ?>  
             <tr>
        <td><?php the_title( '<h5 style="font-size: 16px;" class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h5>' ); ?></td>
              <td><?php the_field('tent'); ?></td>
              <td><?php the_field('laadimise_kp'); ?> <strong>-</strong>  <?php the_field('mahalaadimine'); ?><br></td>
              <td><?php the_field('from'); ?><strong>-</strong><?php the_field('to'); ?></td>
        </tr>
                    <?php endwhile; wp_reset_query(); ?>
          </tbody>
    
    
    
    
    
        </table>
    </div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多