I spent about an hour searching for this. I couldn't find anything solid so I came up with an option myself. This is for people who have long Summary View List. For example, I have a summary view list of up to 130 taxonomy terms depending if there is any content in them.
This is dynamic, so if you have 10 or 100 it will always split the column in 2 with half on one side and half on the other with the remainder on the left.
Example;
[1] | [4]
[2] | [5]
[3] |
I wanted the list to be two column and since they show up as just <li> there was some stuff to add to the template before the css would work. Its not the cleanest but it validates as XHTML and works with any number of items. I set this to only turn into columns if there are 20 or more items in the list. That way there would be at least 10 and 10 on each side.
First, create a view summary theme file. I created views-view-summary.tpl.php and put it in my theme folder. I imagine you could make this file specific to each view if you didn't want two column layout on every view summary.
<?php
// $Id: views-view-summary.tpl.php,v 1.6 2009/01/07 19:21:34 merlinofchaos Exp $
/**
* @file views-view-summary.tpl.php
* Default simple view template to display a list of summary lines
*
* @ingroup views_templates
*/
?>
<div class="item-list">
<ul class="views-summary">
<?php
$totalrows = count($rows); // Counts No. of Rows
$half = round($totalrows / 2); // Split rows into 2 for two column
$rownumber = 0; // Sets first row number
?>
<?php foreach ($rows as $row): ?>
<?php
/* Split the row names into either column 1 or column 2 */
if ($totalrows >= 20): // Set the limit for column split
if ($rownumber < $half) {
$listid = views_column_1;
} else {
$listid = views_column_2;
}; endif; ?>
<li class="<?php print $listid; /* print column number*/ ?>"><a href="<?php print $row->url; ?>"><?php print $row->link; ?></a>
<?php if (!empty($options['count'])): ?>
(<?php print $row->count?>)
<?php endif; ?>
</li>
<?php $rownumber++; /* Incriment row number to the next value */ endforeach; ?>
</ul>
</div>
Step 2
Add the css to your style sheet. You might have to make some changes to fit your theme.
.item-list ul li.views_column_1 {
display:block;
float:left;
width:280px;
}
.item-list ul li.views_column_2 {
display:block;
}
Even though this validates it probably doesn't work at all on IE 6 so some rules would have to be added if your concerned about that.
Hope this helps.
- Jayson
Comments
I'm encountering the same
I'm encountering the same problem, but this time, i'm using tables.
Just wondering, does the $listid and view_column_# applies in the tables?
Thanks
Thanks for posting. I was
Thanks for posting.
I was looking for this kind of functionality.
---~~~***~~~---
aac
Three Column Summary View List
I had to make a three column one for a few hundred terms in Bartik, Drupal 7. The original code above rendered quite a mess in that theme and so here is a modified one for my use case. Instead of labelling each LI element I have opted to just create three discrete UL lists instead. Not semantically correct but it gets the job done.
To put into views-view-summary--VIEWNAME.tpl.php
CSS Stylesheet