Posted By

gd6d on 11/18/09


Tagged

wordpress content split


Versions (?)

Automatically output the content in two columns


 / Published in: PHP
 

URL: http://www.wprecipes.com/wordpress-hack-automatically-output-the-content-in-two-columns?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Wprecipes+%28WpRecipes.com%3A+Daily+recipes+to+cook+with+WordPress%29

  1. This code is poweful but definitely easy to implement. Just paste it on your functions.php file and it will automatically output your post content in columns.
  2. Your post content will be splitted on <h2> tags.
  3.  
  4.  
  5. function my_multi_col($content){
  6. $columns = explode('<h2>', $content);
  7.  
  8. $i = 0;
  9.  
  10. foreach ($columns as $column){
  11. if (($i % 2) == 0){
  12. $return .= '<div class="content_left">' . "\n";
  13. if ($i > 1){
  14. $return .= "<h2>";
  15. } else{
  16. $return .= '<div class="content_right">' . "\n <h2>";
  17. }
  18. $return .= $column;
  19. $return .= '</p></div>';
  20. $i++;
  21. }
  22.  
  23. if(isset($columns[1])){
  24. $content = wpautop($return);
  25. }else{
  26. $content = wpautop($content);
  27. }
  28. echo $content;
  29. }
  30. add_filter('the_content', 'my_multi_col');
  31.  
  32.  
  33. Don't forget to add the following styles to your style.css file
  34.  
  35.  
  36. .content_right, .content_left{
  37. float:left;
  38. width:45%;
  39. }
  40.  
  41. .content_left{
  42. padding-right:5%;
  43. }

Report this snippet  

You need to login to post a comment.