php - Looping through categories in WordPress -


i have number of products, displayed in different categories when ticked.

now, trying achieve, images shown depending on categories clicked.

example.

if clicked category a, image (a) shown.

i doing code shows below.

<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>      <?php      $terms = wp_get_post_terms( get_the_id(), 'type' );     $term_class = '';     if ( isset( $terms[0] ) ) {          $term_class = $terms[0]->slug;     }     ?> <ul>             <li class="linoheight" style="margin-left:45px !important;"><img class="<?php echo $term_class; ?>-new" src="<?php bloginfo('stylesheet_directory'); ?>/images/acoustic-icon-small.png" alt="" width="30px" height="30px" style="display:none;"></li>             <li class="linoheight"><img class="<?php echo $term_class; ?>-new" src="<?php bloginfo('stylesheet_directory'); ?>/images/hard-wired-icon-small.png" alt="" width="30px" height="30px" style="display:none;"></li>             <li class="linoheight"><img class="<?php echo $term_class; ?>-new" src="<?php bloginfo('stylesheet_directory'); ?>/images/radio-icon-small.png" alt="" width="30px" height="30px" style="display:none;"></li>         </ul> 

so, checkbox selected, , create class 'categorya-new.

in css, category display:block, displays icon.

now, issue having, <?php echo $term_class;?>-new getting 1 of categories, means if category selected, category b , c still showing images.

i have feeling issue loop, have ideas?

you need hide , show object if onclick unique id of item should passed jquery or javascript function , show item eg, if have

  • item 1
  • item 2
  • item 3

these 3 fields have unique id,s in them 1- 2- etc need use jquery hit after placing unique id @ ul first catch in between li,s :

$("#list-of-items li").click(function(){      var current_clicked_li_index = $(#list-of-items li).index(this);     // use .each loop in jquery  $("#list-of-items li img").each(function( loopindex ) {      if(current_clicked_li_index != loopindex){        $(this).hide();     }else{      $(this).show();     }  });     }); 

note: don't forget use jquery library.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -