【问题标题】:Wordpress & Fancybox - Loop issue? - fancybox keeps reloading pageWordpress 和 Fancybox - 循环问题? - fancybox 不断刷新页面
【发布时间】:2010-08-21 19:44:20
【问题描述】:

问题页面:www.kendraschaefer.com/mandapop(中间细栏中的图像问题)

嗨,

我正在开发一个新的 Wordpress 模板,但在使用 Fancybox 时遇到了问题。我试图在上面页面的中间细栏中获取图片,当点击时,会在带有附加帖子数据的fancybox中弹出。

它大部分工作正常 - 第一次点击,没问题。点击一张图片,帖子会在一个fancybox中弹出。但是关闭fancybox再试一次,你会注意到帖子加载了一次,然后再次加载。单击另一个,这一次帖子加载多次。 (不要点击太多次,你的浏览器会崩溃)。听起来像一个递归问题,但我不确定我哪里出错了。

我尝试使用其他弹出插件,如 Facebox 和 Lightbox,但也遇到了同样的问题,所以它一定是我的循环或什么的。我还注释掉了页面上的所有其他 javascript 以查看是否存在冲突 - 仍然存在问题。

这是我的代码(有两个循环 - 一个用于图库图片,一个用于博客条目):

<div id="homeGalleryCol">
<div id="homeGalleryContent">
<?php 
query_posts('post_type=galleryimage&posts_per_page=7');

if(have_posts()) : while(have_posts()) : the_post(); ?>
        <div class="singlePhotoPost">
        <h3 class="galleryListDate"><?php the_time('M d'); ?></h3>
                <a href="<?php the_permalink(); ?>" class="fancybox"><?php the_post_thumbnail('gallery-pic-thumbnail'); ?></a>
        </div><!-- end singlePhotoPost -->
    <?php endwhile; ?>
<?php endif; ?>
</div><!-- end homeGalleryContent -->
</div><!-- end homeGalleryCol -->

<div id="thinRightCol">
<div id="rightColContent">
        <div id="blogListColWrapper">
    <div id="blogListCol">


<?php 
query_posts('posts_per_page=3');

global $more;
$more = 0;


if(have_posts()) : while(have_posts()) : the_post(); ?>
        <div class="singlePost">
        <h3 class="blogListDate"><?php the_time('M d'); ?></h3>
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
        <h2 class="postTitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <?php the_content('<span class="moretext">&nbsp;</span>'); ?>
        </div><!-- end singlePost -->

    <?php endwhile; ?>  
    <?php endif; ?>
    </div><!-- end blogListCol -->
    </div><!-- end blogListColWrapper -->

</div><!-- end rightColContent -->
</div><!-- end thinRightCol -->

非常感谢。

【问题讨论】:

  • 如果您将内容加载到 iFrame 中,问题是否仍然存在?
  • 不确定,我试试看。

标签: php jquery wordpress loops fancybox


【解决方案1】:

您似乎删除了实际输出。你能恢复它,我会让你知道发生了什么吗?谢谢。

【讨论】:

    【解决方案2】:

    试试这个功能&lt;?php wp_reset_postdata(); ?&gt;

    因为此函数用于在使用新的 WP_Query 的辅助查询循环之后恢复主查询循环的全局 $post 变量。它将 $post 变量恢复到主查询中的当前帖子。

    示例:http://pastebin.com/kSEg5JPg
    关注&lt;?php wp_reset_postdata(); ?&gt;

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多