Long category descriptions in wordpress
Here is the outline of what I did to get some (translated) text displayed at the beginning of every category page. This is mostly a reminder to myself in order to be able to redo it in the unlikely case I upgrade Wordpress and have to go through it once again.
- Add the column to the categories table.
ALTER TABLE wp_categories ADD COLUMN category_long_description LONGTEXT NOT NULL DEFAULT '' CHARACTER SET utf8 COLLATE utf8_general_ci AFTER category_description;
Actually I intended to usecategory_descriptionfor this, but in my template it is used as the link’stitlein the category listing on the sidebar. - Create a file
category.phpin the theme’s directory. In my case it almost a copy ofarchive.php, but with the following line added:
<div class="categorydescription"><?php category_long_description(); ?></div>
- Add that function (
category_long_description()) towp-includes/template-functions-category.php. Here is the code:
/**
* Returns the long description for a given category
*
* @param int $category Category identifier. Leave empty to default to current category.
*/
function category_long_description($category = 0) {
global $cat;
if (!$category) $category = $cat;
$category = & get_category($category);
return apply_filters('category_long_description', $category->category_long_description, $category->cat_ID);
}
- Tell polyglot to hook to the newly created filter to translate the text in the table. And by the way, tell it to hook to the filter
category_descriptionas well, because it should already be there. Editplugins/polyglot.phpand add:
// category descriptions should not have <more> tags. That's why we don't use lang_picker_respect_more().
add_filter('category_description', 'lang_picker',1);
add_filter('category_long_description', 'lang_picker',1);
-
Last, modify the control panel to add the form field for the categories’ descriptions. The hack is so easy that it just deserves light comment: in file
wp-admin/category.phpadd thetextareain a couple of places, name itcategory_long_description, add the matching$category_long_descriptionvariable everywhere it is needed. Simple copy&paste&edit of the code forcategory_descriptionwill work. - Done. You can check that it works (or at least it should!) browsing some of the categories on this site (I haven’t added descriptions to all of them)

