Advertisement
srikat

my-custom-functions.php

Oct 17th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.08 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: My Custom Functions
  4.  * Plugin URI: http://yoursite.com
  5.  * Description: This is an awesome custom plugin with functionality that I'd like to keep when switching things.
  6.  * Author: Sridhar Katakam
  7.  * Author URI: http://yoursite.com
  8.  * Version: 0.1.0
  9.  */
  10.  
  11. /* Place custom code below this line. */
  12.  
  13. class My_Genesis_Featured_Post extends Genesis_Featured_Post {
  14.  
  15.     function widget( $args, $instance ) {
  16.  
  17.         global $wp_query, $_genesis_displayed_ids;
  18.  
  19.         extract( $args );
  20.  
  21.         //* Merge with defaults
  22.         $instance = wp_parse_args( (array) $instance, $this->defaults );
  23.  
  24.         echo $before_widget;
  25.  
  26.         //* Set up the author bio
  27.         if ( ! empty( $instance['title'] ) )
  28.             echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
  29.  
  30.         $query_args = array(
  31.             'post_type' => 'post',
  32.             'cat'       => $instance['posts_cat'],
  33.             'showposts' => $instance['posts_num'],
  34.             'offset'    => $instance['posts_offset'],
  35.             'orderby'   => $instance['orderby'],
  36.             'order'     => $instance['order'],
  37.         );
  38.  
  39.         //* Exclude displayed IDs from this loop?
  40.         if ( $instance['exclude_displayed'] )
  41.             $query_args['post__not_in'] = (array) $_genesis_displayed_ids;
  42.  
  43.         $wp_query = new WP_Query( $query_args );
  44.  
  45.         if ( have_posts() ) : while ( have_posts() ) : the_post();
  46.  
  47.             $_genesis_displayed_ids[] = get_the_ID();
  48.  
  49.             genesis_markup( array(
  50.                 'html5'   => '<article %s>',
  51.                 'xhtml'   => sprintf( '<div class="%s">', implode( ' ', get_post_class() ) ),
  52.                 'context' => 'entry',
  53.             ) );
  54.  
  55.             $image = genesis_get_image( array(
  56.                 'format'  => 'html',
  57.                 'size'    => $instance['image_size'],
  58.                 'context' => 'featured-post-widget',
  59.                 'attr'    => genesis_parse_attr( 'entry-image-widget' ),
  60.             ) );
  61.  
  62.             if ( $instance['show_image'] && $image )
  63.                 printf( '<a href="%s" title="%s" class="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), esc_attr( $instance['image_alignment'] ), $image );
  64.  
  65.             if ( ! empty( $instance['show_gravatar'] ) ) {
  66.                 echo '<span class="' . esc_attr( $instance['gravatar_alignment'] ) . '">';
  67.                 echo get_avatar( get_the_author_meta( 'ID' ), $instance['gravatar_size'] );
  68.                 echo '</span>';
  69.             }
  70.  
  71.             if ( $instance['show_title'] )
  72.                 echo genesis_html5() ? '<header class="entry-header">' : '';
  73.  
  74.                 if ( ! empty( $instance['show_title'] ) ) {
  75.  
  76.                     if ( genesis_html5() )
  77.                         printf( '<h2 class="entry-title"><a href="%s" title="%s">%s</a></h2>', get_permalink(), the_title_attribute( 'echo=0' ), get_the_title() );
  78.                     else
  79.                         printf( '<h2><a href="%s" title="%s">%s</a></h2>', get_permalink(), the_title_attribute( 'echo=0' ), get_the_title() );
  80.  
  81.                 }
  82.  
  83.                 if ( ! empty( $instance['show_byline'] ) && ! empty( $instance['post_info'] ) )
  84.                     printf( genesis_html5() ? '<p class="entry-meta">%s</p>' : '<p class="byline post-info">%s</p>', do_shortcode( $instance['post_info'] ) );
  85.  
  86.             if ( $instance['show_title'] )
  87.                 echo genesis_html5() ? '</header>' : '';
  88.  
  89.             if ( ! empty( $instance['show_content'] ) ) {
  90.  
  91.                 echo genesis_html5() ? '<div class="entry-content">' : '';
  92.  
  93.                 if ( 'excerpt' == $instance['show_content'] ) {
  94.                     the_excerpt();
  95.                 }
  96.                 elseif ( 'content-limit' == $instance['show_content'] ) {
  97.                     the_content_limit( (int) $instance['content_limit'], esc_html( $instance['more_text'] ) );
  98.                 }
  99.                 else {
  100.  
  101.                     global $more;
  102.  
  103.                     $orig_more = $more;
  104.                     $more = 0;
  105.  
  106.                     the_content( esc_html( $instance['more_text'] ) );
  107.  
  108.                     $more = $orig_more;
  109.  
  110.                 }
  111.  
  112.                 echo genesis_html5() ? '</div>' : '';
  113.  
  114.             }
  115.  
  116.             genesis_markup( array(
  117.                 'html5' => '</article>',
  118.                 'xhtml' => '</div>',
  119.             ) );
  120.  
  121.         endwhile; endif;
  122.  
  123.         //* Restore original query
  124.         wp_reset_query();
  125.  
  126.         //* The EXTRA Posts (list)
  127.         if ( ! empty( $instance['extra_num'] ) ) {
  128.             if ( ! empty( $instance['extra_title'] ) )
  129.                 echo $before_title . esc_html( $instance['extra_title'] ) . $after_title;
  130.  
  131.             $offset = intval( $instance['posts_num'] ) + intval( $instance['posts_offset'] );
  132.  
  133.             $query_args = array(
  134.                 'cat'       => $instance['posts_cat'],
  135.                 'showposts' => $instance['extra_num'],
  136.                 'offset'    => $offset,
  137.             );
  138.  
  139.             $wp_query = new WP_Query( $query_args );
  140.  
  141.             $listitems = '';
  142.  
  143.             if ( have_posts() ) {
  144.                 while ( have_posts() ) {
  145.                     the_post();
  146.                     $_genesis_displayed_ids[] = get_the_ID();
  147.                     $listitems .= sprintf( '<li><a href="%s" title="%s">%s</a></li>', get_permalink(), the_title_attribute( 'echo=0' ), get_the_title() );
  148.                 }
  149.  
  150.                 if ( mb_strlen( $listitems ) > 0 )
  151.                     printf( '<ul>%s</ul>', $listitems );
  152.             }
  153.  
  154.             //* Restore original query
  155.             wp_reset_query();
  156.         }
  157.  
  158.         if ( ! empty( $instance['more_from_category'] ) && ! empty( $instance['posts_cat'] ) )
  159.             printf(
  160.                 '<p class="more-from-category"><a href="%1$s" title="%2$s">%3$s</a></p>',
  161.                 esc_url( get_category_link( $instance['posts_cat'] ) ),
  162.                 esc_attr( get_cat_name( $instance['posts_cat'] ) ),
  163.                 esc_html( $instance['more_from_category_text'] )
  164.             );
  165.  
  166.         echo $after_widget;
  167.  
  168.     }
  169.  
  170. }
  171.  
  172. /* Place custom code above this line. */
  173. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement