This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

http://wp.smashingmagazine.com/2011/10/14/advanced-layout-te

By: a guest on Oct 14th, 2011  |  syntax: PHP  |  size: 1.40 KB  |  views: 665  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // http://wp.smashingmagazine.com/2011/10/14/advanced-layout-templates-in-wordpress-content-editor/
  3.  
  4. // Gets inner HTML for each column, omits the column div so we can apply markup if needed
  5.     function get_inner_html( $node ) {
  6.       foreach($node->childNodes as $value) {
  7.           $html .= $node->ownerDocument->saveXML($value, LIBXML_NOEMPTYTAG);
  8.       }
  9.  
  10.       return $html;
  11.     }
  12.  
  13.            $posts = get_posts(array(
  14.                 'numberposts' => 1,
  15.                 'post_type'   => 'my_custom_post'
  16.             ));
  17.  
  18.             foreach($posts as $post) :
  19.                 setup_postdata($post);
  20.  
  21.                 // Apply content filter to preserve <p> tags
  22.                 $content = get_the_content();
  23.                 $content = apply_filters('the_content', $content);
  24.  
  25.                 $doc = new DOMDocument();
  26.                 $doc->loadHTML($content);
  27.  
  28.                 $xpath = new DOMXPath($doc);
  29.  
  30.                 // Find the divs via xpath
  31.                 $col_1 = get_inner_html($xpath->query('//div[@class="content-col-1"]')->item(0));
  32.                 $col_2 = get_inner_html($xpath->query('//div[@class="content-col-2"]')->item(0));
  33.                 $col_3 = get_inner_html($xpath->query('//div[@class="content-col-3"]')->item(0));
  34.  
  35.                 // Now use your columns as needed!
  36.                 ?>
  37.                 <div class="content-col-1">
  38.                     <div class="content">
  39.                         <?php echo $col_1; ?>
  40.                     </div>
  41.                 </div>
  42.  
  43.  
clone this paste RAW Paste Data