Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Spun content-home.php version 1

By: a guest on Dec 27th, 2013  |  syntax: PHP  |  size: 1.31 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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(); ?> -->