Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // http://wp.smashingmagazine.com/2011/10/14/advanced-layout-templates-in-wordpress-content-editor/
- // Gets inner HTML for each column, omits the column div so we can apply markup if needed
- function get_inner_html( $node ) {
- foreach($node->childNodes as $value) {
- $html .= $node->ownerDocument->saveXML($value, LIBXML_NOEMPTYTAG);
- }
- return $html;
- }
- $posts = get_posts(array(
- 'numberposts' => 1,
- 'post_type' => 'my_custom_post'
- ));
- foreach($posts as $post) :
- setup_postdata($post);
- // Apply content filter to preserve <p> tags
- $content = get_the_content();
- $content = apply_filters('the_content', $content);
- $doc = new DOMDocument();
- $doc->loadHTML($content);
- $xpath = new DOMXPath($doc);
- // Find the divs via xpath
- $col_1 = get_inner_html($xpath->query('//div[@class="content-col-1"]')->item(0));
- $col_2 = get_inner_html($xpath->query('//div[@class="content-col-2"]')->item(0));
- $col_3 = get_inner_html($xpath->query('//div[@class="content-col-3"]')->item(0));
- // Now use your columns as needed!
- ?>
- <div class="content-col-1">
- <div class="content">
- <?php echo $col_1; ?>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement