Split category boards into two columns

Started by shadowpt, February 13, 2012, 03:21:09 AM

Previous topic - Next topic

shadowpt

Hi there and thank you in advance for taking your time with me.

I am trying to split the category boards into 2 columns instead of just plain rows.

So far I have managed to set only the main details inside one td element (board title, posts and topics number and a brief description).
So far so good, I even managed to remove the other 3 columns and I am now left with just 1 per row (and it can also be changed in its own width).

Now my problem is that the php code responsible for that same part is inside a foreach loop



foreach ($category['boards'] as $board)
{
echo '
<tr id="board_', $board['id'], '" class="windowbg2">
<td class="info">
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a> <span>(<strong>', comma_format($board['posts']), '</strong> ', $board['is_redirect'] ? $txt['redirects'] : $txt['posts'], ' / <strong>', $board['is_redirect'] ? '' : comma_format($board['topics']) . '</strong> ' . $txt['board_topics'], ')</span>';

</td>
</tr>';
}


The above code does this:

Category 1





board1
board2
board3
board4

And I am having a really hard time trying to turn it into this:

Category 1





board1board2
board3board4

Which sets 2 boards per each row.

Does anyone know how can I achieve this? I have been searching everywhere for this and so far found nothing.

shadowpt

After a long javascript nostalgic study I have found the solution and implemented it into the php code and I will post it for anyone that wants to achieve the same display:


$i = 0;
foreach ($category['boards'] as $board)
{

if($i % 2) {
echo '
<td class="info">
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a> <span>(<strong>', comma_format($board['posts']), '</strong> ', $board['is_redirect'] ? $txt['redirects'] : $txt['posts'], ' / <strong>', $board['is_redirect'] ? '' : comma_format($board['topics']) . '</strong> ' . $txt['board_topics'], ')</span>';

// Has it outstanding posts for approval?
if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
echo '
<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';

echo '

<p>', $board['description'] , '</p>';

// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
if (!empty($board['moderators']))
echo '
<p class="moderators">', count($board['moderators']) == 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p></td></tr>';
$i = 0;
} else {
echo '
<tr id="board_', $board['id'], '" class="windowbg2">
<td class="info" onclick="window.location=\'', $board['href'], '\'">
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a> <span>(<strong>', comma_format($board['posts']), '</strong> ', $board['is_redirect'] ? $txt['redirects'] : $txt['posts'], ' / <strong>', $board['is_redirect'] ? '' : comma_format($board['topics']) . '</strong> ' . $txt['board_topics'], ')</span>';

// Has it outstanding posts for approval?
if ($board['can_approve_posts'] && ($board['unapproved_posts'] || $board['unapproved_topics']))
echo '
<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';

echo '

<p>', $board['description'] , '</p>';

// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
if (!empty($board['moderators']))
echo '
<p class="moderators">', count($board['moderators']) == 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $board['link_moderators']), '</p></td>';
$i++;
}


The above code needs to be inserted after
<tbody class="content" id="category_', $category['id'], '_boards">';


and before of
// Show the "Child Boards: ". (there's a link_children but we're going to bold the new ones...)


This is for SMF v2.0.2 and you also need to edit the CSS file and add this in the index.css


table.table_list tbody.content {
    display: block;
}


What this code does is to check if the loop (foreach()) Has run once or twice already, depending the number that it is running, it will write a specific part of code and this will result in the final effect that you can see below




Advertisement: