根据WP代码和WP初学者教程,在输入脚本之后,站点有一个Javascript错误:未定义的ReferenceError: imagesLoaded
其他许多人也有这个问题。
链接:http://www.wpbeginner.com/wp-themes/how-to-use-masonry-to-add-pinterest-style-post-grid-in-wordpress/
发布于 2014-07-24 09:46:30
跟着同一篇文章,遇到了同样的问题;作者(乔希·波洛克)在他的博客上发布了一个后续行动。
从本质上讲,WP3.9中的砖石是供您使用的,所以在functions.php中您所需要的就是:
add_action( 'wp_enqueue_scripts', 'slug_masonry' );
function slug_masonry( ) {
wp_enqueue_script('masonry'); // note this is not jQuery
}然后初始化:
//set the container that Masonry will be inside of in a var
var container = document.querySelector('#masonry-loop');
//create empty var msnry
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
msnry = new Masonry( container, {
itemSelector: '.post'
});
});发布于 2014-06-17 10:37:59
如果您使用上述链接中的代码,那么将wp_enqueue_script('masonry')替换为wp_enqueue_script('jquery-masonry')。试着让我知道。
https://wordpress.stackexchange.com/questions/149841
复制相似问题