toxiccosmos

2column function

Jan 8th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php function my_multi_col_v2($content){
  2.     // run through a couple of essential tasks to prepare the content
  3.     $content = apply_filters('the_content', $content);
  4.     $content = str_replace(']]>', ']]&gt;', $content);
  5.  
  6.     // the first "more" is converted to a span with ID
  7.     $columns = preg_split('/(<span id="more-\d+"><\/span>)|(<!--more-->)<\/p>/', $content);
  8.     $col_count = count($columns);
  9.  
  10.         if($col_count == 2) {
  11.             for($i=0; $i<$col_count; $i++) {
  12.                 // check to see if there is a final, if not add it
  13.                 if(!preg_match('/<\/p>\s?$/', $columns[$i]) ) {
  14.                     $columns[$i] .= '';
  15.                 }
  16.                 // check to see if there is an appending, if there is, remove
  17.                 $columns[$i] = preg_replace('/^\s?<\/p>/', '', $columns[$i]);
  18.                 // now add the div wrapper
  19.                 $columns[$i] = '<div class="dynamic-2col-'.($i+1).'">'.$columns[$i].'</div>';
  20.             }
  21.             $content = join($columns, "\n").'<div class="clear"></div>';
  22.         }
  23.  
  24.         if($col_count == 3) {
  25.             for($i=0; $i<$col_count; $i++) {
  26.                 // check to see if there is a final, if not add it
  27.                 if(!preg_match('/<\/p>\s?$/', $columns[$i]) ) {
  28.                     $columns[$i] .= '';
  29.                 }
  30.                 // check to see if there is an appending, if there is, remove
  31.                 $columns[$i] = preg_replace('/^\s?<\/p>/', '', $columns[$i]);
  32.                 // now add the div wrapper
  33.                 $columns[$i] = '<div class="dynamic-3col-'.($i+1).'">'.$columns[$i].'</div>';
  34.             }
  35.             $content = join($columns, "\n").'<div class="clear"></div>';
  36.         }
  37.     else {
  38.         // this page does not have dynamic columns
  39.         $content = wpautop($content);
  40.     }
  41.     // remove any left over empty tags
  42.     $content = str_replace('', '', $content);
  43.     return $content;
  44. }
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment