Two columns layout for node content
kone23 - June 16, 2009 - 18:21
Hello,
I want to display the body of some of my nodes in a two-column layout automatically.
So if the number of words is under a certain limit, the body is diplayed in a single-column, but if it is long enough, then it is split in two columns.
I have been looking for this for a while but could not find any solution.
I have tried panels, composite layout, which efficiently bring to multiple column layouts, but then one cannot split the body into the two columns.
I run out of ideas, I hope someone will be able to help me.
Thank you in advance
"Is a hippopotamus a hippopotamus, or just a really cool Opotamus?"
Mitch Hedberg

Help :)
I am posting another comment here, hoping to get an answer to my first question.
Here is a snippet that does the trick for drupal 4. What about Drupal 6 ?
It is supposed to be easier, yet I could not find any trick for that or any module.
I really need your help, any help
cheers :)
Solution ?
see the following post, I made a msitake
Solution ?
Hello,
I feel quite alone in this thread, probably because the answer to my question is so obvious that no one thinks that it is worth replying my posts.
Anyway, I have decided to keep my efforts here by sharing with you a solution that I found this afternoon, after hours of deep and intense reflection.
So let me sum up what I actually wanted :
the body of a specific content type, created with cck, displayed into two columns and if two long, continued on further pages but still displayed into a two column layout.
So here is how I did:
First, I used the paging module, for cutting my contents into pages.
Second, I had still to cut my nodes' contents into columns.
I added the following function to my template.php :
<?php
function drupalicious_convert2columns ($colcontent) {
$coloutput = "";
$string = "<columns>";
$columns = explode($string,$colcontent); // cut the text for splitting the body into columns
$i = 0;
foreach($columns as $cle=>$valeur){ //go through the array and add div to contents when necessary
if ($i == 0) {
$coloutput .= $valeur;
$i ++;
}
else if ($i == 1) {
$coloutput .= "<div class=\"column_".$i."\">".$valeur."</div>";
$i = 2;
}
else {
$coloutput .= "<div class=\"column_".$i."\">".$valeur."</div>";
$i = 1;
}
}
return $coloutput;
}
?>
This function simply cuts the node content around tags that I add to the body field of my nodes :
<column>and then if necesssary, surrounds the pieces of content with a div and a css class reference.So each time I want the node content to be cut, I simply add a
<column>tag into the body field of my node. Moreover, when I add the<!--pagebreaker-->tag to specify the paging module I need a page break, I add just after this one my created tag<column>so that I can find my two column layout into the following pages.Then I edited my node-"content type name".tpl.php and called the newly created function this way :
<?php
<div class="content">
<php
$output = drupalicious_convert2columns ($content);
print $output;
>
</div>
?>
Finally I just had to give styles to my new created divs and make them columns.
Some of you will think : but why doesn't he count the words into the content and split both in columns and in pages using word numbers (paging enables it, knowing how many words could fit in one div, one could simply (I have seen such a snippet for drupal4) develop a function implementing a count of the words.
I have in my content types to display "blockquotes" of different styles and font-sizes. For that matter, I can't rely on a static word capacity for my div. So I have to place my own tags, and check with the preview how it looks like. Without these blockquotes, i would have probably gone for the count and automatic way.
I don't know if this will help anybody, probably not. Yet I would be curious to hear your criticisms about my solution to either improve it, or be convinced to opt for another one, more simple, efficient and reliable.
...
Glad you found a solution, I'm going to put some more thought into this, certainly its a handy feature although I've felt multi column content seldom works that well on the web, but certainly has its place when needed.
Professional Drupal Design and Theme Services
...
Yes, I agree with you, multi-column can be annoying. I am developing an online magazine, and with my graphic designer we found it could be a good option for some of our articles.
I'm still working on my solution, trying to improve it.
If you can give me any feedback, I would really appreciate it.
I am still very surprised no module has yet been developed for doing that. Maybe if I get better at PHP, I will create the "multi col" module :) probably in a couple decades...
...
Yeah, I'm surprised as well, I would have thought there would be an Input Filter type module like the pagination module you are using, which would be a good solution.
Professional Drupal Design and Theme Services