Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress邮报。将图像列为砌体网格_Wordpress_Jquery Masonry - Fatal编程技术网

Wordpress邮报。将图像列为砌体网格

Wordpress邮报。将图像列为砌体网格,wordpress,jquery-masonry,Wordpress,Jquery Masonry,我在谷歌上到处搜索,没有找到解决这个问题的好办法。我想做的是在帖子中创建一个类似砖石的网格,帖子中的所有图像都应该在砖石网格中。如何实现这一点?您可以使用此解决方案,可以很好地控制图像在内容中的放置位置,并且很容易管理库及其图像 使用此过滤器禁用默认样式: add_filter( 'use_default_gallery_style', '__return_false' ); 然后使用创建网格。这个插件有很好的文档记录,是最常见的用于创建砌体网格的插件,因此您应该可以使用这个插件 记住要设计图

我在谷歌上到处搜索,没有找到解决这个问题的好办法。我想做的是在帖子中创建一个类似砖石的网格,帖子中的所有图像都应该在砖石网格中。如何实现这一点?

您可以使用此解决方案,可以很好地控制图像在内容中的放置位置,并且很容易管理库及其图像

使用此过滤器禁用默认样式:

add_filter( 'use_default_gallery_style', '__return_false' );
然后使用创建网格。这个插件有很好的文档记录,是最常见的用于创建砌体网格的插件,因此您应该可以使用这个插件


记住要设计图库的样式,这样它就可以与砌体插件一起工作。以下是您将使用的两个选择器,.gallery(是每个图库的容器)和.gallery item(是图库中每个图像的容器)。

注意:有了这个想法,您可以在图库中或内容中获取所有附加的图像

首先,让我们在主题中添加砖石

wp_enqueue_script( 'masonry' );
wp_enqueue_script( 'masonry', '//cdnjs.cloudflare.com/ajax/libs/masonry/4.1.1/masonry.pkgd.min.js' );
然后将此javascript代码添加到页脚或custom.js文件中的某个主题中

jQuery(window).load(function() {

  var container = jQuery('#mas-maincontainer');
  var msnry = new Masonry(container, {
    itemSelector: '.mas-item',
    columnWidth: '.mas-item',
  });

});
现在,让我们把所有的图片都附加到你想要的帖子上

$attachments = get_children(array('post_parent' => $post->ID,
                        'post_status' => 'inherit',
                        'post_type' => 'attachment',
                        'post_mime_type' => 'image'));

foreach($attachments as $att_id => $attachment) {
    $full_img_url = wp_get_attachment_url($attachment->ID);
    //Here is your HTML to grid your images... 
   // Remember your images should be between <div id="mas-maincontainer"></div>

}

这就是全部想法,希望它对你有用

如果你不是开发人员,你可以将此或此用于你的图库,如果你是开发人员,请告诉我,然后我可以给你一个完整的指南。我是开发人员!哈哈。开发人员应该投入更多的精力,不要问太多太宽泛的问题。@CBroe感谢您非常有用的回答!
.mas-item {
width: 50%; // if you want two column 
}
.mas-item {
width: 33%; // if you want three column 
}