我正在建立一个WordPress的网站使用引导,我想创建一个精选的工作部分在我的主页上使用石工来显示我最近3个投资组合项目的缩略图和标题。砌体,WordPress的循环和引导
我希望将投资组合项目以看起来随机的方式放置(类似于:http://studiosweep.com/),而不仅仅是有序的网格格式。我无法弄清楚如何为我的投资组合项目分配不同的宽度,因为它们只是通过wordpress循环在特色工作部分生成。
这里是我的HTML:
<section id="work">
<div class="container-fluid">
<div class="row">
<div class="col-sm-offset-6 col-sm-6 text-center">
<h1>Featured Work</h1>
</div>
</div>
<div class="row" id="ms-container">
<?php query_posts('posts_per_page=3&post_type=work'); ?>
<?php while (have_posts()) : the_post();
$thumbnail = get_field('thumbnail');
$medium = get_field('medium');
$size = "large";
?>
<div class="ms-item col-lg-6 col-md-6 col-sm-6 col-xs-12">
<figure>
<a href="<?php the_permalink(); ?>"><?php echo wp_get_attachment_image($thumbnail, $size); ?></a>
</figure>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class="clearfix"></div>
</div>
<?php endwhile; // end of the loop. ?>
<?php wp_reset_query();
</div>
<div class="clearfix"></div>
</div>
</section>
这里的脚本:
<script type="text/javascript">
jQuery(window).load(function() {
// MASSONRY Without jquery
var container = document.querySelector('#ms-container');
var msnry = new Masonry(container, {
itemSelector: '.ms-item',
columnWidth: '.ms-item',
});
});
</script>
至于CSS,我真的不知道如何去分配不同的列宽,所以我只有这个至今:
.ms-item { width: 38.23%; margin-right: 80px; margin-bottom: 70px; }
任何帮助,将不胜感激!
谢谢!这有点接近我想要的。但是有时候,所有三个缩略图都分配了相同的宽度,并且显示在一列中。有没有办法避免这种情况?也许像总是分配第一个项目宽度1,第二个项目宽度2等等? –
当然!看到更新。 – neoprez