Isotope and WordPress layout integration with custom post type
-
I am trying to create a masonry layout using isotope with a custom post type I created. I have got the basics functioning, but would like to apply the additional grid-item classes to certain posts. I’m wondering if there is a way to call to a certain post number and apply the extra class to it within the structure needed for isotope to work.
Here is the original php:
<?php $story = new Wp_Query(['post_type'=>'story']); if ($story->have_posts()) : while ($story->have_posts()) : $story->the_post(); ?> <a class="grid-item <?php $categories = get_the_category(get_the_id()); foreach ($categories as $category) { echo $category->slug.' '; } ?>" href="<?php the_permalink();?>"> <img src="<?php the_field('story_image'); ?>"> <h3><?php the_title(); ?></h3> <?php the_content(); ?></a> <?php endwhile; endif; ?>
The isotope layout I’m trying to mimic within the php code is would look something like this:
<div class="grid"> <div class="grid-item"></div> <div class="grid-item grid-item--width2"></div> <div class="grid-item"></div> <div class="grid-item grid-item--height2"></div> ... </div>
In other words, is there a way I can have the 3rd and 12th posts have the additional class of “grid-item–width2” and the 6th and 18th posts have the “grid-item–height2” class applied to the
<a>
tag?Let me know if you need additional clarification! Or perhaps there is a way through css that I can do this? Thanks so much for any help you can offer!
- The topic ‘Isotope and WordPress layout integration with custom post type’ is closed to new replies.