Advertisement
catchmahesh

Shortcode in Featured page content - Catch Kathmandu Pro

Nov 20th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.21 KB | None | 0 0
  1. function catchkathmandu_featured_content_page( $options ) {
  2.     global $post;
  3.     $quantity       = $options['homepage_featured_qty'];
  4.     $headline       = $options['homepage_featured_headline'];
  5.     $layouts        = $options['homepage_featured_layout'];
  6.     $number_of_post = 0;        // for number of posts
  7.     $post_list      = array();  // list of valid post ids
  8.  
  9.     $output = '';
  10.  
  11.     //Get valid number of posts
  12.     for( $i = 1; $i <= $quantity; $i++ ){
  13.         if ( isset ( $options['featured_content_page'][ $i ] ) && $options['featured_content_page'][ $i ] > 0 ) {
  14.             $number_of_post++;
  15.  
  16.             $post_list  =   array_merge( $post_list, array( $options['featured_content_page'][ $i ] ) );
  17.         }
  18.     }
  19.  
  20.     //Checking Layout
  21.     if ( 'four-columns' == $layouts  ) {
  22.         $classes = "layout-four";
  23.     }
  24.     else {
  25.         $classes = "layout-three";
  26.     }
  27.  
  28.     if ( !empty( $post_list ) && $number_of_post > 0 ) {
  29.         $loop = new WP_Query( array(
  30.                     'posts_per_page' => $number_of_post,
  31.                     'post__in'       => $post_list,
  32.                     'orderby'        => 'post__in',
  33.                     'post_type'      => 'page',
  34.                 ));
  35.  
  36.         $i=0;
  37.  
  38.         $output .= '<section id="featured-post" class="featured-content-page ' . $classes . '">';
  39.  
  40.         if ( !empty( $headline ) ) {
  41.             $output .= '<h1 id="feature-heading" class="entry-title">' . wp_kses_post( $headline ) . '</h1>';
  42.         }
  43.  
  44.         $output .= '<div class="featued-content-wrap">';
  45.         while ( $loop->have_posts()) : $loop->the_post(); $i++;
  46.             $title_attribute = the_title_attribute( 'echo=0' );
  47.             $content = get_the_content();
  48.             $output .= '
  49.                 <article id="featured-post-' . $i . '" class="post hentry">';
  50.                 if ( has_post_thumbnail() ) {
  51.                     $output .= '
  52.                     <figure class="featured-homepage-image">
  53.                         <a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '">
  54.                         '. get_the_post_thumbnail( $post->ID, 'small-featured', array( 'title' => $title_attribute, 'alt' => $title_attribute, 'class' => 'pngfix' ) ) .'
  55.                         </a>
  56.                     </figure>';
  57.                 }
  58.                 else {
  59.                     $catchkathmandu_first_image = catchkathmandu_get_first_image( $post->ID, 'small-featured', array( 'title' => $title_attribute, 'alt' => $title_attribute, 'class' => 'pngfix' ) );
  60.  
  61.                     if ( '' != $catchkathmandu_first_image ) {
  62.                         $output .= '
  63.                         <figure class="featured-homepage-image">
  64.                             <a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '">
  65.                                 '. $catchkathmandu_first_image .'
  66.                             </a>
  67.                         </figure>';
  68.                     }
  69.                 }
  70.  
  71.                 $output .= '
  72.                     <div class="entry-container">';
  73.                         if ( $content !='') {
  74.                             $output .= the_title( '<header class="entry-header"><h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '">','</a></h1></header>', false );
  75.                             $output .= '<div class="entry-content">' . do_shortcode( $content ) . '</div>';
  76.                             $output .= '<a href="' . esc_url( get_permalink() ) . '" title="' . $title_attribute . '"></a>';
  77.                         }
  78.                     $output .= '
  79.                     </div><!-- .entry-container -->
  80.                 </article><!-- .featured-post-'. $i .' -->';
  81.         endwhile;
  82.  
  83.         wp_reset_postdata();
  84.  
  85.         $output .= '</div><!-- .featued-content-wrap -->';
  86.  
  87.         $output .= '</section><!-- #featured-post -->';
  88.     }
  89.  
  90.     return $output;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement