• Hey guys

    Could somebody help me modify this code so the widgets appear in two columns? Right now the widgets appear next to each other and their width is changed.
    If there is only one widget I would like it to fill the width available. But when there are two, they should have 50% width, when there are three, the third one should be on the next line, etc.

    `if (($count = count($widgets)) < 1 || $count > 6) {
    echo ‘<div class=”uk-width-1-1″>Error: Only up to 6 widgets are supported in this layout. If you need more add your own layout.</div>’;
    return;
    }

    $widths = array(
    array(‘1-1’),
    array(‘2-3’, ‘1-3’),
    array(‘2-4’, ‘1-4’, ‘1-4’),
    array(‘2-5’, ‘1-5’, ‘1-5’, ‘1-5’),
    array(‘2-6’, ‘1-6’, ‘1-6’, ‘1-6’, ‘1-6’),
    array(‘1-6’, ‘1-6’, ‘1-6’, ‘1-6’, ‘1-6’, ‘1-6’)
    );

    foreach ($widgets as $index => $widget) {
    $classes = array();
    $prev = 0;
    foreach ($displays as $class => &$display) {
    if (false !== $pos = array_search($index, $display)) {
    $width = in_array($class, $stacked) ? ‘1-1’ : $widths[count($display)-1][$pos];
    if ($width != $prev) {
    $classes[] = “uk-width”.($class != ‘small’ ? “-{$class}” : ”).”-{$width}”;
    $prev = $width;
    }
    } else {
    $classes[] = “uk-hidden-{$class}”;
    }
    }

    printf(PHP_EOL.'<div class=”%s”>%s</div>’.PHP_EOL, implode(‘ ‘, $classes), $widget);
    }’

  • The topic ‘widgets in two columns’ is closed to new replies.