A fix for phpMyDirectory’s category listing

Over the past few weeks I've been working on a directory website built using phpMyDirectory. Being unfamiliar with the software I've been converting the default theme over to the new design, swapping out the many nested tables for divs in the process. I've managed to remove most of the tables from the theme templates but some remain in the form of generated lists. As I don't want to start fiddling around with the core application files I created this function to tidy up the home page category listings.

My fix will strip out the table and the unecessary ul tags that surround each list element and display the categories as a simple unordered list with the class of category-listing for easy styling.

In the template folder open the index.php and look for the following line:

PHP:
  1. echo $category_table;

Comment this line out and then paste in the code below.

PHP:
  1. function category_table_tidy($category_table) {
  2.     $remove = array (
  3.         '<table border="0" cellpadding="0" cellspacing="0" align="center" width="90%"><tr>',
  4.         '<td valign="top" width="33%"><ul class="category_ul">',
  5.         '<span class="text_large_bold">',
  6.         '<span class="text_large_bold_grey">',
  7.         '&nbsp;',
  8.         '</span>',
  9.         '</ul>',
  10.         '<td>&nbsp;</td></tr></table>'
  11.     );
  12.     $category_table_tidy = str_replace($remove, "", $category_table);
  13.     $category_table_tidy = eregi_replace("\([0-9]\)", " <span>\\0</span>", $category_table_tidy);
  14.     echo '<ul class="category-listing">'.$category_table_tidy.'</ul>';
  15. }
  16. category_table_tidy($category_table);

Leave a Reply

(will not be published)