【发布时间】:2016-08-13 19:19:18
【问题描述】:
我正在使用 bootstrap 构建一个 wordpress 网站,我想在我的主页上使用 masonry 创建一个特色工作部分,以显示我最近 3 个投资组合项目的缩略图和标题。
我希望以看似随机的方式放置投资组合项目(类似于: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;
}
任何帮助将不胜感激!
【问题讨论】:
标签: php css wordpress twitter-bootstrap jquery-masonry