Advertisement
Guest User

Untitled

a guest
Nov 18th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $this_post_id = get_the_ID();
  4.  
  5. // Get the all post content in a variable
  6. $posttext = $post->post_content;
  7.  
  8. $document = DOMDocument::loadHTML($posttext);
  9. $xpath = new DOMXPath($document);
  10.  
  11. # for each link that has an image inside it, set its href equal to
  12. # the image's src.
  13. foreach ($xpath->query('//a/img/..') as $link) :
  14.    
  15.  
  16.     $img = $link->getElementsByTagName('img')->item(0);
  17.     $link_src = $link->getAttribute('href');
  18.     $link_title = $link->getAttribute('title');
  19.     $img_src = $img->getAttribute('src');
  20.  
  21.  
  22.     $theImageSrc = $img_src;
  23.     global $blog_id;
  24.     if (isset($blog_id) && $blog_id > 0) {
  25.         $imageParts = explode('/files/', $theImageSrc);
  26.         if (isset($imageParts[1])) {
  27.             $theImageSrc = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
  28.         }
  29.     }
  30.  
  31.     ?>
  32.  
  33.     <a href="<?php echo $link_src; ?>" rel="lightbox[<?php echo $this_post_id; ?>]" title="<?php if ($link_title) {
  34.         echo $link_title;
  35.     } else { the_title(); } ?>" class="cboxElement">
  36.     <img class="alignleft" src='<?php echo get_bloginfo('template_directory').'/timthumb.php?src=' . $theImageSrc  . '&h=150&w=150'; ?>' height="150" width="150" alt=""/>
  37. </a>
  38. <?php
  39.  
  40. endforeach;
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement