Advertisement
srikat

Untitled

Mar 22nd, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.29 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name
  4. *
  5. * @package Custom_Featured_Post_Widget
  6. * @author Gary Jones
  7. * @license GPL-2.0+
  8. * @link http://gamajo.com/
  9. * @copyright 2013 Gary Jones, Gamajo Tech
  10. */
  11.  
  12. /**
  13. * Custom Featured Post widget class.
  14. *
  15. * @package Custom_Featured_Post_Widget
  16. * @author Gary Jones
  17. */
  18. class Custom_Featured_Post extends Genesis_Featured_Post {
  19.  
  20. /**
  21. * Echo the widget content.
  22. *
  23. * @since 1.0.0
  24. *
  25. * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
  26. * @param array $instance The settings for the particular instance of the widget
  27. */
  28. function widget( $args, $instance ) {
  29.  
  30. global $wp_query, $_genesis_displayed_ids;
  31.  
  32. //* Merge with defaults
  33. $instance = wp_parse_args( (array) $instance, $this->defaults );
  34.  
  35. echo $args['before_widget'];
  36.  
  37. //* Set up the author bio
  38. if ( ! empty( $instance['title'] ) )
  39. echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title'];
  40.  
  41. $query_args = array(
  42. 'post_type' => 'post',
  43. 'cat' => $instance['posts_cat'],
  44. 'showposts' => $instance['posts_num'],
  45. 'offset' => $instance['posts_offset'],
  46. 'orderby' => $instance['orderby'],
  47. 'order' => $instance['order'],
  48. 'ignore_sticky_posts' => $instance['exclude_sticky'],
  49. );
  50.  
  51. //* Exclude displayed IDs from this loop?
  52. if ( $instance['exclude_displayed'] )
  53. $query_args['post__not_in'] = (array) $_genesis_displayed_ids;
  54.  
  55. $wp_query = new WP_Query( $query_args );
  56.  
  57. if ( have_posts() ) : while ( have_posts() ) : the_post();
  58.  
  59. $_genesis_displayed_ids[] = get_the_ID();
  60.  
  61. genesis_markup( array(
  62. 'html5' => '<article %s>',
  63. 'xhtml' => sprintf( '<div class="%s">', implode( ' ', get_post_class() ) ),
  64. 'context' => 'entry',
  65. ) );
  66.  
  67. $image = genesis_get_image( array(
  68. 'format' => 'html',
  69. 'size' => $instance['image_size'],
  70. 'context' => 'featured-post-widget',
  71. 'attr' => genesis_parse_attr( 'entry-image-widget', array ( 'alt' => get_the_title() ) ),
  72. ) );
  73.  
  74. if ( $instance['show_image'] && $image ) {
  75. $role = empty( $instance['show_title'] ) ? '' : 'aria-hidden="true"';
  76. printf( '<a href="%s" class="%s" %s>%s</a>', get_permalink(), esc_attr( $instance['image_alignment'] ), $role, $image );
  77. }
  78.  
  79. if ( ! empty( $instance['show_gravatar'] ) ) {
  80. echo '<span class="' . esc_attr( $instance['gravatar_alignment'] ) . '">';
  81. echo get_avatar( get_the_author_meta( 'ID' ), $instance['gravatar_size'] );
  82. echo '</span>';
  83. }
  84.  
  85. if ( $instance['show_title'] )
  86. echo genesis_html5() ? '<header class="entry-header">' : '';
  87.  
  88. if ( ! empty( $instance['show_title'] ) ) {
  89.  
  90. $title = get_the_title() ? get_the_title() : __( '(no title)', 'genesis' );
  91.  
  92. /**
  93. * Filter the featured post widget title.
  94. *
  95. * @since 2.2.0
  96. *
  97. * @param string $title Featured post title.
  98. * @param array $instance {
  99. * Widget settings for this instance.
  100. *
  101. * @type string $title Widget title.
  102. * @type int $posts_cat ID of the post category.
  103. * @type int $posts_num Number of posts to show.
  104. * @type int $posts_offset Number of posts to skip when
  105. * retrieving.
  106. * @type string $orderby Field to order posts by.
  107. * @type string $order ASC fr ascending order, DESC for
  108. * descending order of posts.
  109. * @type bool $exclude_displayed True if posts shown in main output
  110. * should be excluded from this widget
  111. * output.
  112. * @type bool $show_image True if featured image should be
  113. * shown, false otherwise.
  114. * @type string $image_alignment Image alignment: alignnone,
  115. * alignleft, aligncenter or alignright.
  116. * @type string $image_size Name of the image size.
  117. * @type bool $show_gravatar True if author avatar should be
  118. * shown, false otherwise.
  119. * @type string $gravatar_alignment Author avatar alignment: alignnone,
  120. * alignleft or aligncenter.
  121. * @type int $gravatar_size Dimension of the author avatar.
  122. * @type bool $show_title True if featured page title should
  123. * be shown, false otherwise.
  124. * @type bool $show_byline True if post info should be shown,
  125. * false otherwise.
  126. * @type string $post_info Post info contents to show.
  127. * @type bool $show_content True if featured page content
  128. * should be shown, false otherwise.
  129. * @type int $content_limit Amount of content to show, in
  130. * characters.
  131. * @type int $more_text Text to use for More link.
  132. * @type int $extra_num Number of extra post titles to show.
  133. * @type string $extra_title Heading for extra posts.
  134. * @type bool $more_from_category True if showing category archive
  135. * link, false otherwise.
  136. * @type string $more_from_category_text Category archive link text.
  137. * }
  138. * @param array $args {
  139. * Widget display arguments.
  140. *
  141. * @type string $before_widget Markup or content to display before the widget.
  142. * @type string $before_title Markup or content to display before the widget title.
  143. * @type string $after_title Markup or content to display after the widget title.
  144. * @type string $after_widget Markup or content to display after the widget.
  145. * }
  146. */
  147. $title = apply_filters( 'genesis_featured_post_title', $title, $instance, $args );
  148. $heading = genesis_a11y( 'headings' ) ? 'h4' : 'h2';
  149.  
  150. if ( genesis_html5() )
  151. printf( '<%s class="entry-title"><a href="%s">%s</a></%s>', $heading, get_permalink(), $title, $heading );
  152. else
  153. printf( '<%s><a href="%s">%s</a></%s>', $heading, get_permalink(), $title, $heading );
  154.  
  155. }
  156.  
  157. if ( ! empty( $instance['show_byline'] ) && ! empty( $instance['post_info'] ) )
  158. printf( genesis_html5() ? '<p class="entry-meta">%s</p>' : '<p class="byline post-info">%s</p>', do_shortcode( $instance['post_info'] ) );
  159.  
  160. if ( $instance['show_title'] )
  161. echo genesis_html5() ? '</header>' : '';
  162.  
  163. if ( ! empty( $instance['show_content'] ) ) {
  164.  
  165. echo genesis_html5() ? '<div class="entry-content">' : '';
  166.  
  167. if ( 'excerpt' == $instance['show_content'] ) {
  168. the_excerpt();
  169. }
  170. elseif ( 'content-limit' == $instance['show_content'] ) {
  171. the_content_limit( (int) $instance['content_limit'], genesis_a11y_more_link( esc_html( $instance['more_text'] ) ) );
  172. }
  173. else {
  174.  
  175. global $more;
  176.  
  177. $orig_more = $more;
  178. $more = 0;
  179.  
  180. the_content( genesis_a11y_more_link( esc_html( $instance['more_text'] ) ) );
  181.  
  182. $more = $orig_more;
  183.  
  184. }
  185.  
  186. echo genesis_html5() ? '</div>' : '';
  187.  
  188. }
  189.  
  190. printf( '<a href="%s" class="more-link button">%s</a>', get_permalink(), esc_html__( 'Continue Reading' ) );
  191.  
  192. genesis_markup( array(
  193. 'html5' => '</article>',
  194. 'xhtml' => '</div>',
  195. ) );
  196.  
  197. endwhile; endif;
  198.  
  199. //* Restore original query
  200. wp_reset_query();
  201.  
  202. //* The EXTRA Posts (list)
  203. if ( ! empty( $instance['extra_num'] ) ) {
  204. if ( ! empty( $instance['extra_title'] ) )
  205. echo $args['before_title'] . esc_html( $instance['extra_title'] ) . $args['after_title'];
  206.  
  207. $offset = intval( $instance['posts_num'] ) + intval( $instance['posts_offset'] );
  208.  
  209. $query_args = array(
  210. 'cat' => $instance['posts_cat'],
  211. 'showposts' => $instance['extra_num'],
  212. 'offset' => $offset,
  213. );
  214.  
  215. $wp_query = new WP_Query( $query_args );
  216.  
  217. $listitems = '';
  218.  
  219. if ( have_posts() ) {
  220. while ( have_posts() ) {
  221. the_post();
  222. $_genesis_displayed_ids[] = get_the_ID();
  223. $listitems .= sprintf( '<li><a href="%s">%s</a></li>', get_permalink(), get_the_title() );
  224. }
  225.  
  226. if ( mb_strlen( $listitems ) > 0 )
  227. printf( '<ul>%s</ul>', $listitems );
  228. }
  229.  
  230. //* Restore original query
  231. wp_reset_query();
  232. }
  233.  
  234. if ( ! empty( $instance['more_from_category'] ) && ! empty( $instance['posts_cat'] ) )
  235. printf(
  236. '<p class="more-from-category"><a href="%1$s" title="%2$s">%3$s</a></p>',
  237. esc_url( get_category_link( $instance['posts_cat'] ) ),
  238. esc_attr( get_cat_name( $instance['posts_cat'] ) ),
  239. esc_html( $instance['more_from_category_text'] )
  240. );
  241.  
  242. echo $args['after_widget'];
  243.  
  244. }
  245.  
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement