Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php function my_multi_col_v2($content){
- // run through a couple of essential tasks to prepare the content
- $content = apply_filters('the_content', $content);
- $content = str_replace(']]>', ']]>', $content);
- // the first "more" is converted to a span with ID
- $columns = preg_split('/(<span id="more-\d+"><\/span>)|(<!--more-->)<\/p>/', $content);
- $col_count = count($columns);
- if($col_count == 2) {
- for($i=0; $i<$col_count; $i++) {
- // check to see if there is a final, if not add it
- if(!preg_match('/<\/p>\s?$/', $columns[$i]) ) {
- $columns[$i] .= '';
- }
- // check to see if there is an appending, if there is, remove
- $columns[$i] = preg_replace('/^\s?<\/p>/', '', $columns[$i]);
- // now add the div wrapper
- $columns[$i] = '<div class="dynamic-2col-'.($i+1).'">'.$columns[$i].'</div>';
- }
- $content = join($columns, "\n").'<div class="clear"></div>';
- }
- if($col_count == 3) {
- for($i=0; $i<$col_count; $i++) {
- // check to see if there is a final, if not add it
- if(!preg_match('/<\/p>\s?$/', $columns[$i]) ) {
- $columns[$i] .= '';
- }
- // check to see if there is an appending, if there is, remove
- $columns[$i] = preg_replace('/^\s?<\/p>/', '', $columns[$i]);
- // now add the div wrapper
- $columns[$i] = '<div class="dynamic-3col-'.($i+1).'">'.$columns[$i].'</div>';
- }
- $content = join($columns, "\n").'<div class="clear"></div>';
- }
- else {
- // this page does not have dynamic columns
- $content = wpautop($content);
- }
- // remove any left over empty tags
- $content = str_replace('', '', $content);
- return $content;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment