Table of Contents for WordPress plugins

Posted by Gary King on July 14, 2007
Categories: programming, web

Do you have a lot of WordPress plugins and want an easier way of browsing them all? Would a Table of Contents for all of them help you browse through them faster? Then this WordPress plugin modification is for you!

First of all, here’s how it will look like in the end (I’ve hidden some plugins that I’d prefer not to appear in the screenshot):

picture-1.png

I can’t call this a WordPress Plugin because it requires that you modify some files instead of having me just give you a file to upload and active. The reason for this is because WordPress doesn’t make it easy for me to implement this functionality any other way. What this means is that you have to modify one file yourself (which is completely harmless!) and whenever you upgrade your installation of WordPress, you’ll have to re-implement this modification again.

I submitted this modification as a patch to WordPress and they may or may not implement it as a built-in feature - who knows? If not, then it’d at least be nice of them to give me a hook to use so I can convert this modification into a plugin.

Anyways, on with the show!

Installing this modification

If you know how to use patch files, then download and use this file on your installation of WordPress.

Otherwise, to install this modification, open up your /wp-admin/plugins.php file and find this line:


echo '</p>';
} else {


Below that, add this:



echo '<style type="text/css">
table#plugins-table-of-contents { border: 1px solid #ccc; width: 100%; margin-bottom: 10px; }
table#plugins-table-of-contents ul { list-style-type: none; }
</style>';
$number_of_plugins = count($plugins);
$i = 1;

foreach ($plugins as $plugin_file => $plugin_data)
{
$plugins[$i] = $plugin_data; $plugins[$plugin_file] = array_merge($plugin_data, array(’order’ => $i));
$i++;
}

$table_columns = 5;
$plugins_per_table = ceil(count($plugins) / 2 / $table_columns);


echo '<h3>Plugins Table of Contents for ' . (count($plugins) / 2) . ' plugins</h3><table id="plugins-table-of-contents"><tr>';

$k = 1;
$starting_plugin = $plugins_per_table;

for ($i = 1; $i <= $table_columns; $i++)
{
echo '<td valign="top"><ul>';
for ($j = $k; $j <= $starting_plugin; $j++)

{
$plugins[$k]['order'] = $k;
echo '<li>' . $k . '. <a href="plugins.php#plugin-' . $k . '">' . $plugins[$k]['Name'] . ‘</a></li>’;

if ($k == $number_of_plugins)
break;
$k++;
}
$starting_plugin += $plugins_per_table;
echo '</ul></td>';

}

echo '</tr></table>';

for ($i = 1; $i <= $number_of_plugins; $i++)

{
unset($plugins[$i]);
}


And then find


<tr $style>


And replace it with


<tr $style id=\"plugin-{$plugin_data['order']}\”>


And we’re all done! Hopefully that’s not too hard for most people.I’ve also submitted several other patches recently if you want to check them out:

Popularity: 72% [?]

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Michael Vu Wednesday, July 18 2007 at 4:05 am EDT #

    Awesome! Thanks!

Comments