« August 08, 2003 | Main | August 11, 2003 »

Columns in Category Archive Listing

Yeah, kinda geeky, but I'm proud of this. Here's my code to make the category archive listing off to the side of the main page set itself into two columns, thus saving some significant vertical space on the page. I'm sure it could have been more elegant, but it ain't bad for my first whack at PHP, particularly when mixed with the MovableType tags.

<MTArchiveList archive_type="Category">
<?php $category_archives["<$MTArchiveTitle$>"] = "<$MTArchiveLink$>"; ?>
</MTArchiveList>
<?php
$values = count($category_archives);
if ((floor($values / 2) * 2) == $values) {
    $row_count = $values / 2;
}
else {
    $row_count = floor($values / 2) + 1;
}
?>
<table class="sidetable">
<?php $values = count($category_archives);
if ((floor($values / 2) * 2) == $values) {
    $row_count = $values / 2;
}
else {
    $row_count = floor($values / 2) + 1;
}
?>
<table class="sidetable">
<?php
$i = 0;
foreach ($category_archives as $title => $link) {
    $titles[$i] = $title;
    $links[$i] = $link;
    $i++;
}

for ($i = 0; $i < $row_count; $i++) {
    echo "<tr class=\"sidetable\">\n";
        $second = $i + $row_count;
        echo "<td class=\"lsidetable\"><a href=\"$links[$i]\" title=\"$titles[$i]\">$titles[$i]</a></td>\n";
        echo "<td class=\"rsidetable\"><a href=\"$links[$second]\" title=\"$titles[$second]\">$titles[$second]</a></td>\n";
    echo "</tr>\n";
}
?>
</table>
</div>

The associated style sheet excerpt is here:

table.sidetable {
    border-collapse: collapse;
    table-layout: auto;
    border: 0;
    text-align: center;
}

tr.sidetable {
}

td.lsidetable {
    border-right: 2px ridge;
    border-left: 0;
    padding-left: 0;
    padding-right: 2em;
    text-align: right;
    padding-left: 2em;
}

td.rsidetable {
    border-right: 0;
    border-left: 2px ridge;
    padding-left: 2em;
    padding-right: 0;
    text-align: left;
}

Posted 08/10/2003 17:45 by Fritz | Comments (0) | TrackBack

Feedback form complete

I have completed the Feedback form, including my first "real" PHP script. Woohoo!

Posted 08/10/2003 13:41 by Fritz | Comments (0) | TrackBack