Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. <!-- Thumbnail from Custom Field, Post first image or default thumbnail -->
  2. <div class="slide">
  3. <a href="<?php the_permalink() ?>" rel="bookmark">
  4. <?php
  5. $images = get_children(array('post_parent'=>$post->ID, 'post_status'=>'inherit', 'post_type'=>'attachment', 'post_mime_type'=>'image', 'order'=>'ASC', 'orderby'=>'menu_order'));
  6.  
  7. $PostContent = $post->post_content;
  8. $ImgSearch = '|<img.*?src=[\'"](.*?)[\'"].*?>|i';
  9. preg_match_all($ImgSearch, $PostContent, $PostImg);
  10. $ImgNumber = count($PostImg[0]);
  11.  
  12. if (get_post_meta($post->ID, "slide", true)) {
  13. ?>
  14. <img src="<?php echo get_post_meta($post->ID, "slide", true); ?>" alt="<?php the_title(); ?>" />
  15. <?php
  16. } elseif (get_post_meta($post->ID, "slide", true)) {
  17.  
  18. ?>
  19. <img src="<?php echo get_post_meta($post->ID, "slide", true); ?>" alt="<?php the_title(); ?>" />
  20. <?php
  21. } elseif ($images) {
  22. $count = 1;
  23. foreach ($images as $id=>$image) {
  24. if ($count === 1) {
  25. $img = wp_get_attachment_thumb_url($image->ID);
  26. $link = get_permalink($post->ID);
  27. print "\n\n".'<img src="'.$img.'" alt="" />';
  28. }
  29. $count++;
  30. }
  31. } else {
  32.  
  33. ?>
  34. <img src="<?php bloginfo('stylesheet_directory');?>/img/slide.png" alt=""/><?php } ?>
  35. </a>
  36. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement