dragunoff

wpquestions.com, ID = 3611(2)

Dec 27th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. add_filter( 'post_class', 'wpq_filter_post_class' );
  3.  
  4. function wpq_filter_post_class( $classes ) {
  5.    
  6.     if( is_singular() ) {
  7.        
  8.         global $post;
  9.        
  10.         $taxonomies = get_taxonomies( array( 'public' => true ) , 'names', 'and' );
  11.  
  12.         if ( is_array($taxonomies) ) {
  13.             foreach ( $taxonomies as $taxonomy ) {
  14.                 if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
  15.                     foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) {
  16.                         if ( empty($term->slug ) )
  17.                         continue;
  18.                         if ( 'post_tag' == $taxonomy )
  19.                         $classes[] = 'tag-' . sanitize_html_class( $term->slug, $term->term_id );
  20.                         else
  21.                         $classes[] = sanitize_html_class( $taxonomy->name, $taxonomy ) . '-' . sanitize_html_class( $term->slug, $term->term_id );
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.     }
  27.    
  28.     return $classes;
  29.    
  30. }
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment