【发布时间】:2015-09-27 15:08:06
【问题描述】:
判断前请阅读
是的,我完全知道我的问题的低级标题。但是,我无法将其更改为具有更多解释性标题的内容。所以如果你有工作头衔,请告诉我。
好的,那我们来回答这个问题。我在这个部分使用同位素,并在 Chrome 开发人员中遇到了这个烦人的错误。我看不到任何与此问题相关的错误,但由于这是一个错误,我需要修复它(痴迷)。
Uncaught TypeError: b.isotope is not a function
我正在为我的网站使用以下代码:
Isotope.js
jQuery(function ($) {
var $container = $('#isotope-list'); //The ID for the list with all the blog posts
$container.isotope({ //Isotope options, 'item' matches the class in the PHP
itemSelector : '.item',
layoutMode : 'masonry'
});
//Add the class selected to the item that is clicked, and remove from the others
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
//When an item is clicked, sort the items.
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
});
PHP
<?php if ( $the_query->have_posts() ) : ?>
<div id="isotope-list">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$termsArray = get_the_terms( $post->ID, "category"); //Get the terms for this particular item
$termsString = ""; //initialize the string that will contain the terms
foreach ( $termsArray as $term ) { // for each term
$termsString .= $term->slug.' '; //create a string that has all the slugs
}
?>
<div class="<?php echo $termsString; ?> item col-md-4">
<ul class="grid cs-style-3">
<li>
<figure>
<?php // 'item' is used as an identifier (see Setp 5, line 6) ?>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('frontpage_thumb');
} ?>
<figcaption class="lefttext">
<h3><?php the_title(); ?></h3>
<span class="offgrey"><?php echo(types_render_field( "produkt", array( 'raw' => true) )); ?> / <?php echo(types_render_field( "produsert", array( 'raw' => true) )); ?></span>
<a href="<?php the_permalink() ?>" rel="bookmark" class="smoothtrans">Se prosjekt</a>
</figcaption>
</figure>
</li>
</ul>
</div> <!-- end item -->
<?php endwhile; ?>
</div> <!-- end isotope-list -->
<script src="<?php bloginfo('stylesheet_directory'); ?>/js/toucheffects.js"></script>
<?php endif; ?>
该网站可以找到here。
我已尝试查找它,但正如我所见,它没有理由将 b.isotope 变成 #isotope-list。我已经在网上搜索了几次有效的解决方案,但我找不到任何解决方案。一篇帖子说它与 Bootstrap 有关。更新到 Bootstrap 后,我仍然看到问题,所以我相信 Bootstrap 没有错误。但是,Boostrap 和 Isotope 之间可能存在以下连接问题:
$container
也许这与 Bootstrap 中的某些内容有关,因为容器在我的网站上多次使用。
总结一下:
- Chrome 开发者中显示错误
- 没有视觉错误
- 使用 Wordpress、Isotope 和 Bootstrap
- 页面可以找到here
您知道任何可行的解决方案或想法吗?请告诉我。
我真的建议查看链接以寻找解决方案,因为它可能感染了我没有在此处发布的其他 js。
【问题讨论】:
-
同位素是否在其他页面中起作用?看起来它没有正确安装,所以您的 jquery 对象没有它作为可用功能。
-
您的脚本包含的顺序是什么? - 您能否发布您的
<head>的相关部分(或插入脚本的任何位置 - 也可能靠近结束</body>标签)? -
http://www.vekvemedia.no/wp-content/themes/vekvemedia/js/isotope.js被包含两次...看起来您没有包含使用 correct methods 的脚本 -
还包含两次 JQuery。请注意,WordPress 也可以自动提供 JQuery。
-
很抱歉没有在您发表评论的同时回复。我没想到会有这样的参与。谢谢。我会尝试你的想法并回复你。
标签: php jquery wordpress twitter-bootstrap