Advertisement
Guest User

Spun content-home.php version 1

a guest
Dec 27th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package Spun
  4.  * @since Spun 1.0
  5.  */
  6.  
  7. /*
  8.  * Get the post thumbnail; if one does not exist, try to get the first attached image.
  9.  * If no images exist, let's print the post title instead.
  10.  */
  11.  
  12. global $post;
  13. $postclass = '';
  14.  
  15. if ( '' != get_the_post_thumbnail() ) {
  16.     $thumb = get_the_post_thumbnail( $post->ID, 'post-thumbnail attachment-home-post', array( 'title' => esc_attr( get_the_title() ) ) );
  17. }
  18. else {
  19.     $args = array(
  20.                 'post_type' => 'attachment',
  21.                 'numberposts' => 1,
  22.                 'post_status' => null,
  23.                 'post_mime_type' => 'image',
  24.                 'post_parent' => $post->ID,
  25.             );
  26.  
  27.     $first_attachment = get_children( $args );
  28.  
  29.     if ( $first_attachment ) {
  30.         foreach ( $first_attachment as $attachment ) {
  31.             $thumb = wp_get_attachment_image( $attachment->ID, 'post-thumbnail', false, array( 'title' => esc_attr( get_the_title() ) ) );
  32.         }
  33.     }
  34.     else {
  35.         $thumb = '<span class="no-thumbnail thumbnail-title">' . get_the_title() . '</span>';
  36.         $postclass = 'no-thumbnail';
  37.     }
  38. }
  39. ?>
  40.  
  41. <article id="post-<?php the_ID(); ?>" <?php post_class( $postclass ); ?>>
  42.     <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo $thumb; ?></a>
  43.         <span class="date"><?php the_date()?></span>
  44. </article><!-- #post-<?php the_ID(); ?> -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement