Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. function siiimple_query( $args ) {
  2.     $q = array();
  3.     if( $args['terms'] )
  4.         $q['tax_query'] = array(
  5.             array(
  6.                 'taxonomy' => 'category',
  7.                 'field' => 'id',
  8.                 'no_found_rows' => true,
  9.                 'terms' => $args['terms'],
  10.             )
  11.         );
  12.     $q['post_offset'] = isset( $args['post_offset']) ? ((int) $args['post_offset']) : 0;
  13.  
  14.     $q['posts_per_page'] = $args['number'];
  15.     $q['offset'] = isset( $args['page'] ) ? ( (int) $args['page'] - 1 ) * (int) $args['number'] : '';
  16.    
  17.     $wp_query = new WP_Query( $q );
  18.    
  19.     $count = count($wp_query->posts);
  20.    
  21.     if ( $wp_query->have_posts() ) :
  22.         $num = 1;
  23.         $html = '';
  24.        
  25.         while ( $wp_query->have_posts() ) :        
  26.             $wp_query->the_post();
  27.            
  28.             $grid = '';
  29.             if( $args['column'] == 1 )
  30.                 $grid = 12;
  31.             elseif( $args['column'] == 2 )
  32.                 $grid = 6;
  33.             elseif( $args['column'] == 3 )
  34.                 $grid = 4;
  35.             elseif( $args['column'] == 4 )
  36.                 $grid = 3;
  37.                
  38.                
  39.             $grid_name = '';
  40.             if( $args['column'] == 1 )
  41.                 $grid_name = 'siiimple-12';
  42.             elseif( $args['column'] == 2 )
  43.                 $grid_name = 'siiimple-6';
  44.             elseif( $args['column'] == 3 )
  45.                 $grid_name = 'siiimple-4';
  46.             elseif( $args['column'] == 4 )
  47.                 $grid_name = 'siiimple-3';
  48.            
  49.             /*CONTACT WIDGET AUTHOR ABOUT THIS*/               
  50.             //if( $args['column'] != 1 && $num == 1 || $num % $args['column'] == 1 )
  51.            
  52.             if ( $args['show_gallery'] ) {
  53.             $html .= '<div class="show-gallery">';
  54.             } else {
  55.             $html .= '<div class="row-siiimple">';
  56.            
  57.             }
  58.                
  59.             if ( $args['show_gallery'] ) { 
  60.            
  61.             //Changed to 100 from 1 ask author
  62.             $class = $args['column'] != 100 ? "cp-item-gallery col-sm-$grid col-md-$grid col-lg-$grid $grid_name" : "cp-item-gallery";
  63.             } else {
  64.             $class = $args['column'] != 100 ? "cp-item col-sm-$grid col-md-$grid col-lg-$grid $grid_name" : "cp-item";
  65.             }
  66.            
  67.             $html .= ( stripslashes ("<div class='$class'>". siiimple_process_post( $args ) . "</div>"));
  68.            
  69.             //if( $args['column'] != 1 && $num % $args['column']== 0 || $num == $count )
  70.             $html .= '</div>';
  71.            
  72.             $num++;        
  73.         endwhile;
  74.        
  75.         if ( $args['show_gallery'] ) {
  76.         $html .= "<div class='clear' style='clear:both; height:0px;'></div>";
  77.         } else {
  78.         $html .= "<div class='clear' style='clear:both; height:1px;'></div>";
  79.         }
  80.        
  81.         if ( $args['load_more'] && $wp_query->max_num_pages > 1 ) {
  82.             $page = isset( $args['page'] ) ? $args['page'] : 1;
  83.             $html .= "<div class='load-more' data-id='{$args['id']}' data-page='$page'>";
  84.                 $html .= "<p>-&nbsp;&nbsp;Load More&nbsp;&nbsp;-</p><a href='#'>".  __( '<span>&#43;</span>', SIIIMPLE_TEXTDOMAIN ) ."</a>";
  85.             $html .= "</div>";
  86.         }      
  87.        
  88.         //Added for infinite scroll for sections
  89.         //$html .= "<div class='fetch'>". next_posts_link( __( 'Load more posts', 'siiimple' ) ) . "</div>";
  90.        
  91.         wp_reset_postdata(); // reset the post globals as this query will shakes the party
  92.    
  93.     else:  
  94.         if( current_user_can('manage_options') )
  95.             $html = __( 'There is no post for the current settings or the end of page.', SIIIMPLE_TEXTDOMAIN );
  96.     endif;
  97.  
  98.     return $html;  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement