Im trying to use Isotope(http://isotope.metafizzy.co/) to filter my WordPress posts,
http://i44.tinypic.com/fco55k.jpg this is how my site looks like, i would like to filter posts depending on a post category so i need to add a class name to each post and then filter it using isotope
<li><a href="#" data-filter="*">show all</a></li>
<li><a href="#" data-filter=".design">design</a></li>
<li><a href="#" data-filter=".typo">typography</a></li>
those are the names of my categories, and then i would like to add class name of a post depending on a category he is in.
<div id="main">
<?php
$args = array('orderby' => 'rand' );
$random = new WP_Query($args); ?>
<?php if(have_posts()) : ?><?php while($random->have_posts()) : $random->the_post(); ?>
<a href="<?php the_permalink() ?>"> <div id="img" class="<?php $category = get_the_category();
echo $category[0]->cat_name; ?>">
<?php
the_post_thumbnail();?>
<h1><?php the_title(); ?></h1>
</div></a>
and javascript im using
<script type="text/javascript">
jQuery(window).load(function(){
jQuery('#main').isotope({
masonry: {
columnWidth: 20
},
});
$('#filters a').click(function(event){
var selector = $(this).attr('data-filter');
$('#main').isotope({ filter: selector });
return false;
});
});
</script>
Not sure you got Isotope and filters working yet ??
There are 2 things I think you missed
the Filters need to be wrapped in a class (so that the jquery can be actioned by the click on the a links) like so:
NB the data-filter are CaSe sensitive (so they won’t work if they don’t match your WordPress categories or whatever you use.
Here’s the original code from Isotope documentation
Here’s the code changed for WordPress
NB put this in after the rest of your isotope script
and note that #options is the class from your filter list in the HTML 🙂
You can see it working at damien.co/isotope
Hope that helped you?
You may want to use this function:
Place this in your functions.php
and then call this function in the file where your isotope container is.
Like:
It will output the correct markup for isotope
So if you create new posts in the backend of WordPress and link categories to them they will show up and be filterable
I too have been attempting to integrate the jQuery Isotope plugin with WP when I stumbled upon this topic. If you still need help here’s how it worked. My method was a little different since I have created a custom post type of projects that I wanted to be filtered by the projects_categories which is a custom taxonomy.
The page template needed the following php for the #projects-filter list and the #projects div to be generated.
And here’s the javascript that works the magic.
First, wrap your post output in a
<div>
, and add the<?php post_class(); ?>
template tag to that<div>
.So, change this:
….to this:
Now, if you read the
post_class()
Codex entry (linked above), you’ll see that, among other classes, this template tag applies acategory-{slug}
class. (For your example categories,post_class()
would addcategory-design
orcategory-typo
.So then, you should just need to target
category-{slug}
to implement the isotope filter.Add the animationEngnine: ‘jquery’ – and the animation will be smoother.