Advertisement
pratikshrestha

Catch Kathmandu Pro: Override Parent Featured Page Content

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