Advertisement
catchmahesh

Featured Grid Content - Clean Box

Jun 5th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. function clean_box_page_grid_content( $options ) {
  2.     $quantity       = $options['featured_grid_content_number'];
  3.  
  4.     global $post;
  5.  
  6.     $clean_box_page_grid_content = '';
  7.     $number_of_page         = 0;        // for number of pages
  8.     $page_list              = array();  // list of valid page ids
  9.  
  10.     //Get number of valid pages
  11.     for( $i = 1; $i <= $quantity; $i++ ){
  12.         if( isset ( $options['featured_grid_content_page_' . $i] ) && $options['featured_grid_content_page_' . $i] > 0 ){
  13.             $number_of_page++;
  14.  
  15.             $page_list  =   array_merge( $page_list, array( $options['featured_grid_content_page_' . $i] ) );
  16.         }
  17.  
  18.     }
  19.  
  20.     if ( !empty( $page_list ) && $number_of_page > 0 ) {
  21.         $get_featured_posts = new WP_Query( array(
  22.             'posts_per_page'    => $quantity,
  23.             'post_type'         => 'page',
  24.             'post__in'          => $page_list,
  25.             'orderby'           => 'post__in'
  26.         ));
  27.  
  28.         $i=1;
  29.  
  30.         while ( $get_featured_posts->have_posts() ) {
  31.  
  32.             $get_featured_posts->the_post();
  33.  
  34.             $title_attribute = the_title_attribute( array( 'before' => __( 'Permalink to:', 'clean-box' ), 'echo' => false ) );
  35.  
  36.             $classes = 'page pageid-' . $post->ID;
  37.  
  38.             if ( 1 == $i ) {
  39.                 $classes .= ' first-cols';
  40.             }
  41.  
  42.             $clean_box_page_grid_content .=
  43.             '<a class="grid-box '. $classes .'" title="' . $title_attribute . '" href="' . get_permalink() . '">';
  44.  
  45.             if ( has_post_thumbnail() ) {
  46.                 if ( 1 == $i ) {
  47.                     $clean_box_page_grid_content .= get_the_post_thumbnail( $post->ID, 'clean-box-featured-grid', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ), 'class'    => 'pngfix' ) );
  48.                 }
  49.                 else{
  50.                     $clean_box_page_grid_content .= get_the_post_thumbnail( $post->ID, 'clean-box-featured-content', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ), 'class' => 'pngfix' ) );
  51.                 }
  52.             }
  53.             else {
  54.                 //Default value if there is no first image
  55.                 $clean_box_image =
  56.                     '<img class="no-image pngfix" src="'.get_template_directory_uri().'/images/gallery/no-featured-image-800x450.jpg" />';
  57.  
  58.                 //Get the first image in page, returns false if there is no image
  59.                 $clean_box_first_image = clean_box_get_first_image( $post->ID, 'medium', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ), 'class' => 'pngfix' ) );
  60.  
  61.                 //Set value of image as first image if there is an image present in the post
  62.                 if ( '' != $clean_box_first_image ) {
  63.                     $clean_box_image =  $clean_box_first_image;
  64.                 }
  65.  
  66.                 $clean_box_page_grid_content .= $clean_box_image;
  67.             }
  68.  
  69.             $clean_box_page_grid_content .= '
  70.                 <div class="caption">
  71.                     <span class="vcenter">
  72.                         <span class="entry-title">
  73.                             ' . the_title('', '', false) . '
  74.                         </span>
  75.                         <span class="more">';
  76.  
  77.                         $clean_box_page_grid_content .=  $options['excerpt_more_text'];
  78.  
  79.                 $clean_box_page_grid_content .= '
  80.                         </span><!-- .more -->
  81.                     </span><!-- .vcenter -->
  82.                 </div><!-- .caption -->
  83.             </a><!-- .grid-box -->';
  84.  
  85.             $i++;
  86.         }
  87.  
  88.         wp_reset_query();
  89.     }
  90.  
  91.     return $clean_box_page_grid_content;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement