当我偶然发现这个主题时,我也一直在尝试将jQuery同位素插件与WP集成。如果你仍然需要帮助,下面是它的工作原理。我的方法有点不同,因为我创建了一个自定义的post类型的项目,我想通过projects\\u类别进行筛选,这是一种自定义的分类法。
页面模板需要以下php才能生成#项目筛选器列表和#项目div。
<?php
$terms = get_terms(\'project_categories\');
$count = count($terms);
if ( $count > 0 ){
echo \'<ul id="projects-filter">\';
echo \'<li><a href="#" data-filter="*">All</a></li>\';
foreach ( $terms as $term ) {
$termname = strtolower($term->name);
$termname = str_replace(\' \', \'-\', $termname);
echo \'<li><a href="#" data-filter="\' . \'.\' . $termname . \'">\' . $term->name . \'</a></li>\';
}
echo \'</ul>\';
}
?>
<?php
$loop = new WP_Query(array(\'post_type\' => \'projects\', \'posts_per_page\' => -1));
$count =0;
?>
<div id="project-wrapper">
<div id="projects">
<?php if ( $loop ) :
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$terms = get_the_terms( $post->ID, \'project_categories\' );
if ( $terms && ! is_wp_error( $terms ) ) :
$links = array();
foreach ( $terms as $term )
{
$links[] = $term->name;
}
$links = str_replace(\' \', \'-\', $links);
$tax = join( " ", $links );
else :
$tax = \'\';
endif;
?>
<?php $infos = get_post_custom_values(\'wpcf-proj_url\'); ?>
<div class="project-item <?php echo strtolower($tax); ?>">
<div class="thumb"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail( \'projects-thumb\' ); ?></a></div>
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p class="excerpt"><a href="<?php the_permalink() ?>"><?php echo get_the_excerpt(); ?></a></p>
<p class="links"><a href="<?php echo $infos[0]; ?>" target="_blank">Live Preview →</a> <a href="<?php the_permalink() ?>">More Details →</a></p>
</div>
<?php endwhile; else: ?>
<div class="error-not-found">Sorry, no portfolio entries for while.</div>
<?php endif; ?>
</div>
<div class="clearboth"></div>
</div> <!-- end #project-wrapper-->
下面是发挥魔力的javascript。
jQuery(document).ready(function(){
var mycontainer = jQuery(\'#projects\');
mycontainer.isotope({
filter: \'*\',
animationOptions: {
duration: 750,
easing: \'liniar\',
queue: false,
}
});
jQuery(\'#projects-filter a\').click(function(){
var selector = jQuery(this).attr(\'data-filter\');
mycontainer.isotope({
filter: selector,
animationOptions: {
duration: 750,
easing: \'liniar\',
queue: false,
}
});
return false;
});
});