0

Is it possible to split the_content() into three equal size columns? I have tried to achive that by getting this code which I found here

                <?php
$content = get_the_content();
$strings = wordwrap($content, (word_count())/3, "<br />"); //Put a {BREAK} every 500 characters
$chunks = explode("<br />", $strings); //Put each segment separated by {BREAK} into an array field

//Printing each chunk in a div
foreach($chunks as $chunk_content) {
    echo "<div class='col-md-4'>";
    echo $chunk_content;
    echo "</div>";
}
?>

and this is the code in my function.php

function word_count() {
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
return $word_count;
}

This creates pieces but there is more than three and therefor the text is still readable horizontally across the columns...... I don't now why it shouldn't work?? Hope someone could take a look!

1 Answer 1

1

What about CSS3 columns? All new browser support it and you can make it beautifully degrade it on old browser. Moreover you can use media queries to make it responsive!

http://www.w3schools.com/css/css3_multiple_columns.asp

2
  • I am using bootstrap for responsive columns but I don't know how to make the_content to split "equally" into thre columns....@MiCc83
    – HannesH
    Commented Jul 5, 2014 at 7:26
  • Just search for css3 columns and you will find it, and then css3 columns polyfill to make it work in older browsers... Commented Jul 5, 2014 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.