Advertisement
downloadtaky

functions/firstimage.php

Mar 22nd, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php // Funzione per mostrare qualunque immagine nel loop
  2. function getImage($num) {
  3.     global $more;
  4.     $more = 1;
  5.     $link = get_permalink();
  6.     $title = get_the_title ();
  7.     $alt = get_the_title ();
  8.     $content = get_the_content();
  9.     $count = substr_count($content, '<img');
  10.     $start = 0;
  11.     for($i=1;$i<=$count;$i++) {
  12.         $imgBeg = strpos($content, '<img', $start);
  13.         $post = substr($content, $imgBeg);
  14.         $imgEnd = strpos($post, '>');
  15.         $postOutput = substr($post, 0, $imgEnd+1);
  16.         $postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '/width="200px" height="200px"/',$postOutput);
  17.         $image[$i] = $postOutput;
  18.         $start=$imgEnd+1;
  19.     }
  20.     if(stristr($image[$num],'<img')) { echo '<a title="'.$title.'" href="'.$link.'">'.$image[$num]."</a>"; }
  21.     $more = 0;
  22. };?>
  23. <?php
  24. function get_post_thumbnail() {
  25. $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
  26. if($files) :
  27. $keys = array_reverse(array_keys($files));
  28. $j=0;
  29. $num = $keys[$j];
  30. $image=wp_get_attachment_image($num, 'large', false);
  31. $imagepieces = explode('"', $image);
  32. $imagepath = $imagepieces[1];
  33. $thumb=wp_get_attachment_thumb_url($num);
  34. print $thumb;
  35. else:
  36. print "http://www.yourdomain.com/wp-content/uploads/2010/02/default-post-thumb.jpg";
  37. endif;
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement