This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

content-home.php

By: a guest on May 5th, 2013  |  syntax: PHP  |  size: 1.47 KB  |  views: 278  |  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', array( 'title' => esc_attr( get_the_title() ) ) );
  17.         $title = '<span class="hometitle">' . esc_attr( get_the_title()) . '</span>';
  18. }
  19. else {
  20.         $args = array(
  21.                                 'post_type' => 'attachment',
  22.                                 'numberposts' => 1,
  23.                                 'post_status' => null,
  24.                                 'post_mime_type' => 'image',
  25.                                 'post_parent' => $post->ID,
  26.                         );             
  27.  
  28.  
  29.         $first_attachment = get_children( $args );
  30.  
  31.         if ( $first_attachment ) {
  32.                 foreach ( $first_attachment as $attachment ) {
  33.                         $thumb = wp_get_attachment_image( $attachment->ID, 'post-thumbnail', false, array( 'title' => esc_attr( get_the_title() ) ) );
  34.                 }
  35.                 $title = '<span class="hometitle">' . esc_attr( get_the_title()) . '</span>';
  36.         }
  37.         else {
  38.                 $thumb = '<span class="no-thumbnail">' . get_the_title() . '</span>';
  39.                 $postclass = 'no-thumbnail';
  40.                 $title = '';
  41.         }
  42. }
  43.  
  44. ?>
  45.  
  46. <article id="post-<?php the_ID(); ?>" <?php post_class( $postclass ); ?>>
  47.         <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  48.               <?php echo $thumb; ?>
  49.               <?php echo $title; ?>
  50.          </a>
  51. </article><!-- #post-<?php the_ID(); ?> -->
clone this paste RAW Paste Data