Advertisement
srikat

Untitled

Aug 28th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. /**
  2.  * Get featured image markup.
  3.  *
  4.  * Only when the single Post or Page has a featured image, and only when
  5.  * showing the first page when the Page or Post is divided into multiple
  6.  * pages using next page quicktag.
  7.  *
  8.  * @author Sridhar Katakam
  9.  * @author Gary Jones
  10.  * @link   http://sridharkatakam.com/display-featured-image-header-minimum-pro/
  11.  *
  12.  * @return  string|bool Image markup if image could be determined
  13.  */
  14. function sk_get_featured_image() {
  15.     // Uncomment the lines below if you want to limit to *just* featured
  16.     // images, and not fallback to first-attached images.
  17.     // if ( ! has_post_thumbnail() ) {
  18.     //  return;
  19.     // }
  20.  
  21.     if ( ! is_page() && ! is_single() ) {
  22.         return;
  23.     }
  24.  
  25.     if ( (int) get_query_var( 'page' ) > 0 ) {
  26.         return;
  27.     }
  28.  
  29.     // If post has no featured image, it will attempt to fallback to
  30.     // first-attached image if the first conditional in this function
  31.     // is commented out.
  32.     return genesis_get_image( 'class=aligncenter' );
  33. }
  34.  
  35. add_action ( 'genesis_entry_header', 'sk_featured_image', 5 );
  36. /**
  37.  * Display Featured image after header.
  38.  *
  39.  * Only on the first page when the Page or Post is divided into multiple
  40.  * using next page quicktag.
  41.  *
  42.  * Scope: static Pages and single Posts.
  43.  *
  44.  * @author Sridhar Katakam
  45.  * @author Gary Jones
  46.  * @link   http://sridharkatakam.com/link-to-your-tutorial
  47.  */
  48. function sk_featured_image() {
  49.     if ( $image = sk_get_featured_image() ) {
  50.         echo '<div class="my-featured-image">' . $image . '<p class="wp-caption-text">' . get_post(get_post_thumbnail_id())->post_excerpt . '</p></div>';
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement