dqoqnmb163241 2018-10-11 08:51
浏览 39

使用fancybox显示帖子内容

I'm trying to display the post content in a fancybox, and it's almost working good except after clicking on the link it shows only the content of the first post.

So I came across the idea to add the posts ID to the data-src, but for some reason my code is not adding the ID.

<ul>
          <?php $args = array('post_type' => 'rm', 'showposts' => 20, 'order' => 'ASC'); $the_query = new WP_Query( $args ); ?>
          <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
          <?php $meta = get_post_meta( $post->ID, 'city_council_candidates', true );

          $postsData[$row]['links'][$i] = [
            'id' => get_the_id(),
          ];

          foreach($postsData as $key => $value) :
            $links = $value['links'];

            echo '<pre>'; echo var_dump($links); echo '</pre>';
          ?>

          <li class="candidates-wrapper col-12 col-sm-12 col-md-4 col-lg-3 col-xl-2">
            <a data-fancybox data-src="#selectableModal-<?php echo $value['id'] ?>" href="javascript:;">
              <div class="candidates-img">
                <?php the_post_thumbnail(); ?>
              </div><!-- .news_img -->
              <div class="candidates-name">
                <?php echo $meta['name']; ?>
              </div>
              <div class="candidates-surname">
                <?php echo $meta['surname']; ?>
              </div>
              <div class="candidates-constituency">
                <?php echo $meta['constituency']; ?>
              </div>

              <div style="display: none;max-width:500px;" id="selectableModal-<?php echo $value['id'] ?>">
                <h2>
                  <?php echo $meta['name']; ?><?php echo $meta['surname']; ?>
                <h2>
                <p>
                  <?php the_content(); ?>
                </p>
              </div>
            </a>
          </li><!-- .news-wrapper -->

          <?php
            endforeach;
            endwhile;
            wp_reset_postdata();
          ?>
        </ul>

As you can see I also added the var_dump function to check if the $links are getting any ID's from the query and the ID's are passed there.

In the console the link looks like this <a data-fancybox="" data-src="#selectableModal-" href="javascript:;">

What did I do wrong?

  • 写回答

2条回答 默认 最新

  • dpz90118 2018-10-11 09:01
    关注

    <div style="display: none; max-width:500px;" id="selectableModal">
      <h2>name + surname<h2>
      <p>content</p>
     </div>

    You shouldn't put the style display:none inline with id="selectableModal" element. it shouldn't be there, it might show the fancybox but not the content for it will not show the content. Maybe override the content with display: block!important; when fancybox shows.

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看