javascript - Isotope Plugin: Only generating filters for specific categories? -
i used tutorial provided alicia ramirez set isotope plugin wordpress page. goal simple masonry layout posts + option filter them.
through tutorial learned how generate filters categories set in backend , subsequently load posts. done piece of code:
<ul id="filters" class="cat-filter"> <li><a href="#" data-filter="*" class="selected">alles</a></li> <?php $terms = get_terms("category"); // categories, can use taxonomy $count = count($terms); // how many they? if ( $count > 0 ){ // if there more 0 terms foreach ( $terms $term ) { // each term: echo "<li><a href='#' data-filter='.".$term->slug."'>" . $term->name . "</a></li>\n"; //create list item current term slug sorting, , name label } } ?> </ul> i know how might able generate filters , load posts of specific set of categories, rather of them. can changing initial piece of code gets categories via $terms = get_terms("category");?
get_terms accepts array of arguments contains parameters specify terms want returned.
you don't how identify specific categories, i'll use term names in example, can change search slug, term id, meta_query or else allowed.
example terms terms named "news" , "events" only
$args = array( 'names' => array( "news", "events")); $terms = get_terms("category", $args); if wanted terms specific ids, use like: $args = array( 'include' => array( 1,4,7 )); // term ids 1,4 , 7 only
Comments
Post a Comment