SpankyAndy Posted May 31, 2010 Posted May 31, 2010 Hi all, I'm trying to split my categories box into a 2 column table with each category link within its own cell, instead of the default list with each category divided by a <br>. For example ... Instead of: Category1<br>Category2<br>Category3<br>Category4<br>etc. Something like: <tr><td>Category1</td><td>Category4</td></tr> <tr><td>Category2</td><td>Category5</td></tr> <tr><td>Category3</td><td>Category6</td></tr> I've tried playing around with categories.php, but I'm struggling to do this. Does anybody have any pointers or possibly know of a contribution that will do this for me? Cheers Andy
SpankyAndy Posted June 6, 2010 Author Posted June 6, 2010 I eventually figured out how to do this, but it involved rewriting most of the includes/boxes/categrories.php script. I'm only a novice, so this may not be the most efficient way to do it, but this seems to work exactly as required, listing the categories alphabetically from top to bottom, rather than left to right. For those who are looking to split their category listing in to two columns, I've copied my new script below. Please note that I only wanted two category columns on the front page, so left categories.php intact for the rest of the site and created categories2.php for the two column layout. As such, a lot of the categories.php functions I didn't require have been stripped out, so I'd recommend using this script as a reference to modify your own, rather than replacing the entire file. Also, please note that I have not tried this with an odd number of categories. I have attempted to correct a potential problem with this, but all my testing was on an even number, so you may need to be careful that there are no problems building the table if the last cell is empty. The categories query and $tree array are the same as the original file, so you should be able to chop and change code quite easily. Cheers Andy <!-- categories //--> <tr> <td><table> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES); new infoBoxHeading($info_box_contents, true, false); //------------------------ $categories_string = '<table>'; $tree = array(); $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name"); $category_row_count = mysql_num_rows($categories_query); $middle_number = (count($category_row_count)-1) / 2; $count = 1; $category_counter = 1; if ($category_row_count %2) { $category_row_count = $category_row_count1 + 1; } while ($categories = tep_db_fetch_array($categories_query)) { $tree[$count] = array('name' => $categories['categories_name'], 'parent' => $categories['parent_id'], 'level' => 0, 'path' => $categories['categories_id'], 'next_id' => false); if ($count != $category_row_count - 1) { $count = $count + 2; } else { $count = 2; } $category_counter++; if (isset($parent_id)) { $tree[$parent_id]['next_id'] = $categories['categories_id']; } $parent_id = $categories['categories_id']; if (!isset($first_element)) { $first_element = $categories['categories_id']; } } $category_counter = 1; while ($category_counter <= $category_row_count) { $cPath_new = 'cPath=' . $tree[$category_counter]['path']; if ($category_counter % 2) { // odd number $categories_string .= '<tr><td class="catmenu" onclick="window.location.href=\'' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '\'" onmouseover="this.className=\'catover\';" onmouseout="this.className=\'catout\';"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . $tree[$category_counter]['name'] . '</a></td>'; } else{ // even number $categories_string .= '<td width="10"></td><td class="catmenu" onclick="window.location.href=\'' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '\'" onmouseover="this.className=\'catover\';" onmouseout="this.className=\'catout\';"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . $tree[$category_counter]['name'] . '</a></td></tr>'; } $category_counter++; if (tep_has_category_subcategories($counter)) { // $categories_string .= ' ...'; } if ($tree[$counter]['next_id'] != false) { tep_show_category2($tree[$counter]['next_id']); } } $categories_string .= '</table>'; $info_box_contents = array(); $info_box_contents[] = array('text' => $categories_string); new infoBox($info_box_contents); //print_r($info_box_contents); ?> </table></td> </tr> <!-- categories_eof //-->
Recommended Posts
Archived
This topic is now archived and is closed to further replies.