【问题标题】:wordpress and isotope masonry suddenly messing upwordpress 和同位素砌体突然搞砸了
【发布时间】:2012-06-13 22:36:17
【问题描述】:

我现在遇到了一个非常令人沮丧的问题。 我正在使用 jquery isotope 制作一个包含在 div 中的水平图像网格,所有这些都在 wordpress 上运行。它已经完美地工作了很长一段时间。这是一个页面,显示某个类别的每个子类别的第一篇文章中的特色图像。 为了使砌体网格正常工作,我一直在使用 php 从每个图像中检索图像大小,并将其作为内联 css 样式放入 div 标记中。正如我所说,它一直在完美地工作。

突然间,我的网站加载时间非常糟糕,一旦页面加载,网格就会变得一团糟。一些同位素元素将在其正确的位置,但有些将完全关闭。检查源代码,我可以看出“关闭”元素的尺寸没有打印在内联 css 中——它们应该通过 php 获得的数字。每个页面加载时哪些 div 关闭似乎是完全随机的。有时他们都会在正确的位置。但最近大多数情况下,3-ish 会关闭。

我刚刚升级到 wordpress 3.3.2 — 升级前后都存在这个问题。

我的托管服务拒绝承认这是他们的问题。我很难相信这一点,因为当网站突然开始混乱时,我没有对任何内容进行任何更改。

即使升级到新版本,Wordpress 安装是否会突然出现问题?

这是我用来让整个网格正常工作的代码:

$args=array(
  'child_of' => '50',
  'orderby' => 'name',
  'order' => 'DESC'
  );
$categories=get_categories($args);
    foreach($categories as $category) {
      $posts=get_posts('showposts=1&cat='. $category->term_id);
      if ($posts) {
        foreach($posts as $post) {
          setup_postdata($post); 

        ?>
        <a class="thumblink" href="<?php the_permalink();?>">
        <?php
            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
              $thumbsize = get_post_custom_values("thumbsize"); // retrieve the wished thumb size, designated in the custom field
              if ( $thumbsize[0] >= 1 && $thumbsize[0] <= 6 ) { // if the thumb size is in the 1 to 6...
          $imglink = wp_get_attachment_image_src( get_post_thumbnail_id(), $thumbsize[0] );
          $size = getimagesize($imglink[0]); // get the width and height of the image in order to work properly with masonry
          echo "<div class='thumbdiv masonrythumb hashover' style='width:$size[0]px;height:$size[1]px'>";
          echo "<div class='hoverobject'>"; //superimposes the content of the post on top of the image on hover
          the_content();
          echo "</div>";
            the_post_thumbnail( $thumbsize[0], array('class' => '' , 'title' => '' ) ); // use the designated thumb size
          echo "</div>";
            }
            }
    ?>
    </a>




        } // foreach($posts
      } // if ($posts
    } // foreach($categories

谁能判断脚本是否存在明显问题导致整个页面加载速度过慢?

非常感谢所有可以帮助我的人。我把头发拉出来了;老实说,我不明白一些一直在工作的东西怎么会突然停止工作。

【问题讨论】:

    标签: php jquery wordpress


    【解决方案1】:

    听起来您的 foreach 语句正在一遍又一遍地运行(因此“加载”时间很慢),因此会导致 DOM 输出出现意外结果。将结束括号(您的最后三行代码)放在 PHP 中,然后回显您的最后一个链接。像这样:

       echo "</a>";
      } // foreach $posts
     } // if $posts
    } // foreach $categories
    ?>
    

    或者,您也可以在结束链接标记的正下方添加&lt;?php。让我知道这是否有效。

    【讨论】:

    • 您好,非常感谢您的回复,但恐怕没有成功!我现在已经在 php 中的 echo 中放置了开始和结束 a-tags,它是一样的。还有其他想法吗?
    • 您是否确保在 php 中也为您的 foreach 语句和 if 语句添加了右括号?根据您的主题设置方式,这可能至关重要。如果是这样,那么在这段代码之前一定有一些东西缺少某种结束标记。仔细检查你的functions.php 和你的header.php(如果你有这些)。还要确保您的第一个开始和最后一个结束 PHP 标记前后没有空格。
    • 你好。右括号都正确嵌套在 php 中。无论如何,这并不能真正解释该页面如何在很长一段时间内运行良好,直到突然混乱而没有人接触任何东西。而且它仍然不断地进进出出。我的 wordpress 网站上还有其他类别页面,它们也都可以正常工作。这真是令人费解。
    【解决方案2】:

    对于任何感兴趣的人,我似乎已经自己解决了这个问题。

    我不太清楚是什么把页面搞砸了,但我可以说wp_get_attachment_image_src()getimagesize() 这两个函数似乎以某种方式相互影响。现在,正确阅读文档后,我意识到wp_get_attachment_image_src() 函数返回一个包含 img 源和宽度和高度的数组,所以我什至不需要 getimagesize() 函数。

    现在网站加载速度很快,而且很好,没有任何 DOM 混乱。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多