Advertisement
ravart108

spun child home content

Dec 14th, 2013
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 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. $url = '';
  15. $custom_link = '';
  16.  
  17. // Get the custom link
  18. if ( function_exists( 'get_custom_field' ) ) {
  19. $custom_link = get_custom_field( 'custom_link' );
  20. } else {
  21. $custom_link = '';
  22. }
  23.  
  24. // Check if the custom link exists
  25. if ( !empty( $custom_link ) ) {
  26.  
  27. //Add in "http://" if it isn't there already
  28. if ( strpos( $custom_link,'http://') === false ){
  29. $custom_link = 'http://' . $custom_link;
  30. }
  31.  
  32. $url = $custom_link;
  33.  
  34. } else {
  35. $url = the_permalink();
  36. }
  37.  
  38.  
  39. if ( '' != get_the_post_thumbnail() ) {
  40. $thumb = get_the_post_thumbnail( $post->ID, 'post-thumbnail', array( 'title' => esc_attr( get_the_title() ) ) );
  41. }
  42. else {
  43. $args = array(
  44. 'post_type' => 'attachment',
  45. 'numberposts' => 1,
  46. 'post_status' => null,
  47. 'post_mime_type' => 'image',
  48. 'post_parent' => $post->ID,
  49. );
  50.  
  51. $first_attachment = get_children( $args );
  52.  
  53. if ( $first_attachment ) {
  54. foreach ( $first_attachment as $attachment ) {
  55. $thumb = wp_get_attachment_image( $attachment->ID, 'post-thumbnail', false, array( 'title' => esc_attr( get_the_title() ) ) );
  56. }
  57. }
  58. else {
  59. $thumb = '<span class="no-thumbnail">' . get_the_title() . '</span>';
  60. $postclass = 'no-thumbnail';
  61. }
  62.  
  63.  
  64. }
  65.  
  66. ?>
  67.  
  68. <article id="post-<?php the_ID(); ?>" <?php post_class( $postclass ); ?>>
  69. <a href="<?php echo $url ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php echo $thumb; ?></a>
  70. </article><!-- #post-<?php the_ID(); ?> -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement