Advertisement
daymobrew

Add one-third to sidebar contents.

Apr 25th, 2016
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. // Only add the 'post_class' filters on the appropriate pages.
  2. // The is_front_page() test was returining an incorrect value on non-front pages!!
  3. add_action('get_header', 'mcl_add_post_class_filters');
  4. function mcl_add_post_class_filters() {
  5.     if (is_front_page()) {
  6.         add_filter( 'post_class', 'mcl_front_page_sidebar_post_class' );
  7.     }
  8.    
  9.     if (is_category()) {
  10.         add_filter( 'post_class', 'be_archive_post_class' );
  11.     }
  12. }
  13.  
  14.  
  15. // Change the front page sidebar items to be in 3 columns.
  16. function mcl_front_page_sidebar_post_class( $classes ) {
  17.     global $wp_query;
  18.     if($wp_query->is_main_query() ) {
  19.         return $classes;
  20.     }
  21.    
  22.     if (!is_front_page()) {
  23.         return $classes;
  24.     }
  25.  
  26.     $classes[] = 'one-third';
  27.     if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 3 )
  28.         $classes[] = 'first';
  29.     return $classes;
  30. }
  31.  
  32.  
  33. // Set the category archive posts to be in 2 columns.
  34. /**
  35.  * Archive Post Class
  36.  * @since 1.0.0
  37.  *
  38.  * Breaks the posts into two columns
  39.  * @link http://www.billerickson.net/code/grid-loop-using-post-class
  40.  *
  41.  * @param array $classes
  42.  * @return array
  43.  */
  44. function be_archive_post_class( $classes ) {
  45.     global $wp_query;
  46.     if( ! $wp_query->is_main_query() ) {
  47.         return $classes;
  48.     }
  49.    
  50.     if (!is_category()) {
  51.         return $classes;
  52.     }
  53.        
  54.     $classes[] = 'one-half';
  55.     if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 2 )
  56.         $classes[] = 'first';
  57.     return $classes;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement