• Posted: 2011-04-08
  • Author: David Vickhoff
  • Tags:

Split up images and text

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
<div class="content-text">
  <h2><?php the_title(); ?></h2>
  <?php
  ob_start();
  the_content('Read the full post',true);
  $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
  ob_end_clean();
  echo $postOutput;
  ?>
</div>
<div class="content-img">
  <?php
  preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
  for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
    echo $beforeEachImage . $matches[1][$i] . $afterEachImage;}?>
</div>

Instructions:

Pulls out all your images in your post and puts it in a separate div.


Share this snippet

If you like this snippet, share it with friends!