Advertisement
Guest User

Spun content-home.php with Custom Circles

a guest
Dec 14th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.                         // Get the link
  59.                         $link = get_custom_field( 'link' );
  60.                        
  61.                         //Add in "http://" if it isn't there already
  62.                         if ( strpos( $link, 'http://' ) === false ) {
  63.                             $link = 'http://' . $link;
  64.                         }
  65.                        
  66.                         // I don't know how to return something useful from
  67.                         // get_custom_field that'll let me know if no image
  68.                         // has been specified, so I'm doing this elongation:
  69.                         // Convert the image to an integer
  70.                         $image_id = (int) get_custom_field( 'image:wrapper');
  71.  
  72.                         //If it's more than zero then it has matched
  73.                         if ( $image_id !== 0 ) {
  74.                                 $thumb = get_custom_field( 'image:to_image_tag' );
  75.                         }
  76.                         else {
  77.                                 $thumb = '<span class="no-thumbnail">' . esc_attr( the_title_attribute( 'echo=0' ) ) . '</span>';
  78.                                 $postclass = 'no-thumbnail';
  79.                         }
  80.  
  81.                         ?>
  82.  
  83. <article id="post-<?php the_ID(); ?>" <?php post_class( $postclass ); ?>>
  84.     <a href="<?php echo $link; ?>" title="<?php the_title() ?>" rel="bookmark">
  85.             <?php echo $thumb; ?>
  86.         </a>
  87. </article><!-- #post-<?php the_ID(); ?> -->
  88.  
  89.                                 <?php
  90.                         }
  91.         }
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement