Advertisement
Guest User

Spun content-home.php with Custom Circles

a guest
Dec 13th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 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', 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">' . 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. </article><!-- #post-<?php the_ID(); ?> -->
  44.  
  45. <?php
  46. /* Get custom circles */
  47.         $args = array(
  48.                 'post_type' => 'custom_circles'
  49.         );
  50.  
  51.         $custom_circles = new WP_Query( $args );
  52.  
  53.         if( $custom_circles->have_posts() ) {
  54.                 while( $custom_circles->have_posts() ) {
  55.  
  56.                         $custom_circles->the_post();
  57.  
  58.                         $link = get_custom_field( 'link' );
  59.  
  60.                         // I don't know how to return something useful from
  61.                         // get_custom_field that'll let me know if no image
  62.                         // has been specified, so I'm doing this elongation:
  63.                        
  64.                         // Convert the image to an integer
  65.                         $image_id = (int) get_custom_field( 'image:wrapper');
  66.  
  67.                         //If it's more than zero then it has matched
  68.                         if ( $image_id !== 0 ) {
  69.                                 $thumb = get_custom_field( 'image:to_image_tag' );
  70.                         }
  71.                         else {
  72.                                 $thumb = '<span class="no-thumbnail">' . esc_attr( the_title_attribute( 'echo=0' ) ) . '</span>';
  73.                                 $postclass = 'no-thumbnail';
  74.                         }
  75.  
  76.                         ?>
  77.  
  78. <article id="post-<?php the_ID(); ?>" <?php post_class( $postclass ); ?>>
  79.     <a href="<?php echo $link; ?>" title="<?php the_title() ?>" rel="bookmark">
  80.             <?php echo $thumb; ?>
  81.         </a>
  82. </article><!-- #post-<?php the_ID(); ?> -->
  83.  
  84.                                 <?php
  85.                         }
  86.         }
  87.  
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement