Advertisement
rejuancse

ceil

Jan 30th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.08 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'wp_ajax_thmloadmore', 'thm_load_more_posts' );
  4. add_action( 'wp_ajax_nopriv_thmloadmore', 'thm_load_more_posts' );
  5. function thm_load_more_posts() {
  6.     global $wpdb; # this is how you get access to the database
  7.  
  8.     $output     = '';
  9.     $posts      = 0;
  10.     $paged      = 1;
  11.     $number     = 3;
  12.     $perpage    = $show_author = $show_date = $show_category = $order = $category = $number = $layout = '';
  13.  
  14.     if(isset( $_POST['perpage'] )){ $perpage = $_POST['perpage']; }
  15.  
  16.     if(isset( $_POST['show_author'] )){ $show_author = $_POST['show_author']; }
  17.     if(isset( $_POST['show_date'] )){ $show_date = $_POST['show_date']; }
  18.     if(isset( $_POST['show_category'] )){ $show_category = $_POST['show_category']; }
  19.     if(isset( $_POST['order'] )){ $order = $_POST['order']; }
  20.     if(isset( $_POST['category'] )){ $category = $_POST['category']; }
  21.     if(isset( $_POST['perpage'] )){ $number = $_POST['perpage']; }
  22.     if(isset( $_POST['paged'] )){ $paged = $_POST['paged']; }
  23.     if(isset( $_POST['layout'] )){ $layout = $_POST['layout']; }
  24.     $offset = $_POST['offset'];
  25.  
  26.     if (isset($category) && $category!='') {
  27.         $idObj  = get_category_by_slug( $category );
  28.         if (isset($idObj) && $idObj!='') {
  29.             $idObj  = get_category_by_slug( $category );
  30.             $cat_id = $idObj->term_id;
  31.             $args = array(
  32.                 'category'          => $cat_id,
  33.                 'orderby'           => 'meta_value_num',
  34.                 // 'meta_key'           => 'themeum_highlight',
  35.                 'order'             => 'DESC',
  36.                 'posts_per_page'    => $number,
  37.                 'paged'             =>ceil($paged)
  38.             );
  39.             $posts = get_posts($args);
  40.         }else{
  41.             echo "Please Enter a valid category name";
  42.             $args = 0;
  43.         }
  44.     }else{
  45.         $args = array(
  46.             'order'             => 'DESC',
  47.             'orderby'           => 'meta_value_num',
  48.             // 'meta_key'           => 'themeum_highlight',
  49.             'posts_per_page'    => $number,
  50.             'paged'             =>ceil($paged)
  51.         );
  52.         $posts = get_posts($args);
  53.     }
  54.  
  55.    
  56.     if(count($posts)>0){
  57.    
  58.         if( $layout == 'style1' ){
  59.             foreach ($posts as $key=>$post): setup_postdata($post);
  60.  
  61.                 $output .= '<div class="themeum-latest-item">';
  62.                 $output .= '<div class="all-highlights-style2-item clearfix">';
  63.                 if ( has_post_thumbnail($post->ID) ) {
  64.                     $output .= '<div class="themeum-overlay-wrap highlight-post-thumb yes">';
  65.                         $output .= '<a href="'.get_permalink($post->ID).'">'.get_the_post_thumbnail($post->ID, 'full', array('class' => 'img-responsive')).'</a>';
  66.                     $output .= '</div>';//col-sm-4
  67.                    
  68.                     $output .= '<div class="highlight-post-content">'; 
  69.                         if ( $show_category == 'yes'){
  70.                             $output .= '<span class="entry-category">';
  71.                             $output .= get_the_category_list(' ', '', $post->ID);
  72.                             $output .= '</span>';
  73.                         }
  74.                         $output .= '<h3 class="entry-title"><a href="'.get_permalink($post->ID).'">'. get_the_title($post->ID) .'</a></h3>';
  75.  
  76.                         if ( $show_author == 'yes'){
  77.                             $output .= '<span class="author">'.__('By ', 'calcio').''.get_the_author_link().'</span>'; 
  78.                         }
  79.                         if ( $show_date == 'yes'){
  80.                             $output .= '<span class="entry-date">';
  81.                             $output .= get_the_date('d M Y', $post->ID);
  82.                             $output .= '</span>';  
  83.                         }  
  84.                        
  85.                     $output .= '</div>';//col-sm-8
  86.                    
  87.                 }else {
  88.                     $output .= '<div class="col-sm-12 latest-post-intro">';
  89.                         if ( $show_category == 'yes'){
  90.                             $output .= '<span class="entry-category">';
  91.                             $output .= get_the_category_list(', ', '', $post->ID);
  92.                             $output .= '</span>';
  93.                         }
  94.                         $output .= '<h3 class="entry-title"><a href="'.get_permalink($post->ID).'">'. get_the_title($post->ID) .'</a></h3>';
  95.  
  96.  
  97.                         if ( $show_author == 'yes'){
  98.                             $output .= '<span class="author">'.__('By ', 'calcio').''.get_the_author_link().'</span>'; 
  99.                         }
  100.                         if ( $show_date == 'yes'){
  101.                             $output .= '<span class="entry-date">';
  102.                             $output .= get_the_date('d M Y', $post->ID);
  103.                             $output .= '</span>';  
  104.                         }  
  105.                        
  106.                     $output .= '</div>';//col-sm-8 
  107.                 }
  108.                 $j++;
  109.                 $output .= '</div>';
  110.                 $output .= '</div>';
  111.  
  112.             endforeach;
  113.         }
  114.  
  115.  
  116.        
  117.         wp_reset_postdata();  
  118.    
  119.     }
  120.  
  121.     echo $output;
  122.  
  123.     wp_die(); # die
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement