【问题标题】:Displaying Custom post type in Lightbox在灯箱中显示自定义帖子类型
【发布时间】:2014-05-13 05:13:37
【问题描述】:

我正在使用 Lightbox Plus Colorbox Worpress 插件尝试在灯箱中而不是在其自己的页面上显示自定义帖子类型。

我使用了以下代码,其中lbp-inline-href-1 是将内容放入灯箱的插件功能:

<?php
//WordPress loop for custom post type
$my_query = new WP_Query('post_type=package&package-category=Kenya&posts_per_page=-1');

while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a class="lbp-inline-link-1" href="#"><?php the_title(); ?></a>
<div style="display:none">

<div id="lbp-inline-href-1" style="padding: 10px;background: #fff">

               <h2><?php the_title(); ?></h2>
               <div class="content">
               <?php the_content(); ?>
               </div>

</div>
</div>  


<?php endwhile;  wp_reset_query(); ?>

代码部分有效,其中内容显示在灯箱中,但是所有帖子标题都链接到相同的第一篇帖子,即。当我单击任何帖子的标题时,所有帖子都会打开一个灯箱并显示相同的内容- 它们都显示第一个帖子内容。

请帮忙

【问题讨论】:

  • 您需要为a 和相关内容div 使用唯一ID。看我的回答here

标签: jquery wordpress lightbox


【解决方案1】:

因为您没有为每个帖子使用唯一 ID。您可以使用以下;

<?php
//WordPress loop for custom post type
$my_query = new WP_Query('post_type=package&package-category=Kenya&posts_per_page=-1');

while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a class="lbp-inline-link-1" href="#post_<?php the_ID; ?>"><?php the_title(); ?></a>
<div style="display:none">

<div id="post_<?php the_ID; ?>" style="padding: 10px;background: #fff">

               <h2><?php the_title(); ?></h2>
               <div class="content">
               <?php the_content(); ?>
               </div>

</div>
</div>  


<?php endwhile;  wp_reset_query(); ?>

我使用hrefdiv 中当前帖子的ID 来打开相关帖子。例如;

<a class="lbp-inline-link-1" href="#post_23"><?php the_title(); ?></a>
<div style="display:none">

<div id="post_23" style="padding: 10px;background: #fff">

               <h2><?php the_title(); ?></h2>
               <div class="content">
               <?php the_content(); ?>
               </div>

</div>
</div> 

如您所见,post_23 匹配

【讨论】:

  • ..谢谢,但上面打开了一个空白模态..模态窗口内没有内容?
  • @user2798091 能否请您提供灯箱的源代码?你看到 div 元素了吗?
猜你喜欢
  • 2022-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-12
  • 2012-09-18
相关资源
最近更新 更多