我用的是同位素。js在我的作品集中展示我的作品。
通过我的循环,我定义了一个先验(使用引导)每个条目的宽度,这对于我的所有条目都是一样的。
How can I assign different widths (col-*) to each post from time to time?
<div class="row grid">
<div class="grid-sizer col-12 col-sm-6"></div><!-- .grid-sizer per Isotope -->
<?php query_posts(array( \'post_type\' => \'portfolio\', \'author\' => get_the_author_meta(\'ID\'), \'showposts\' => 10 ) ); ?>
<?php while (have_posts()) : the_post();
$termsArray = get_the_terms( $post->ID, $taxonomy ); //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="col-12 col-sm-6 <?php echo $termsString; ?> grid-item wow fadeInUp">
<article id="post-<?php the_ID(); ?>" <?php post_class(\'card\'); ?>>
<?php echo get_the_post_thumbnail($post_id, \'large\', array(\'class\' => \'img-fluid card-img-top\')); ?>
<div class="overlay"></div>
<div class="card-body text-right">
<h6 class="card-title"><?php the_title(); ?></h6>
<p>Text description for this item</p>
</div>
<a class="card-link" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"></a>
</article>
</div>
<?php endwhile; ?>
</div>
SO网友:Anson W Han
在立即包装每个帖子的div上,可以使用php随机化值,而不是硬编码col-12
和col-sm-6
课程。
例如,您可以更改
<div class="col-12 col-sm-6 <?php echo $termsString; ?> grid-item wow fadeInUp">
要反映随机化器及其结果,请执行以下操作:
<?php
$randomColClasses = \'col-\' . rand(8,12); //random value between 8-12
$randomColClasses .= \' col-sm-\' . rand(4,8); //random value between 4-8
?>
<div class="<?php echo $randomColClasses . \' \' . $termsString; ?> grid-item wow fadeInUp">