November 11, 2015

How to Add Custom Fields to Joomla Categories in Joomla 2.5 and Joomla 3.0

Custom fields are user-generated fields that allow developers and website admins to categorize galleries, taxonomies, post types, shortcodes, and content more conveniently. Generally speaking, post tables store objects while post meta tables store additional information associated with the objects. If you are a developer, then you probably know that this practice is sometimes wasteful, which is why many people create custom fields in their Joomla database. However, creating custom fields in Joomla database is not really that easy, and you’ll discover why.


Why Create Custom Fields? Creating custom fields is not entirely difficult, but it’s not that easy or straightforward either when it comes to customized plugins. Depending on the Joomla firmware version you are currently using, there are different approaches to creating custom fields. While plugins are available to add custom fields on your database, more often than not, they are not practical, considering your specific needs. Remember that while custom fields can help you organize your data more effectively, they do tend to clog the database. As such, your database may be hard to access sometimes. However, backing up your database and removing any unwanted and unused plugins and extensions can really make a difference. Creating Custom Fields When it comes to the custom fieldset, it is difficult to make them appear on your live site if you are working on content plugins. Recently, while working on adding a shopping cart to a Joomla website, we found out that Joomla has a bug in its code. Well, technically speaking, it’s not really a bug since the code that is used in rendering custom fields is altogether missing in Joomla’s edit template file. In other words, you need a patch that can help you fix the missing code to your database to allow you to create category fields for plugins. Here is a patch that will help you add this fix to help you create additional category fields using Plugins. Open file / administrator/ components/ com_categories/ views/ category/ tmpl/ edit.php Now for Joomla 2.5 add the following code just above line 89:

? 1 form->getFieldsets('attribs'); ?> 2 $fieldSet) : ?> 3 4 label), $name.'-options'); ?> 5 description) && trim($fieldSet->description)) : ?> escape(JText::_($fieldSet->description));?> form->getFieldset($name) as $field) : ?> label; ?> input; ?>

As for Joomla 3.0, add the following code after line 43 ? 1 form->getFieldsets('attribs'); ?> 2 $fieldSet) : ?> label);?> Now just after following code, loadTemplate('options'); ?>

Add the following code for tab content, ? 1 form->getFieldsets('attribs'); ?> 2 $fieldSet) : ?> description) && trim($fieldSet->description)) : ?> escape(JText::_($fieldSet->description));?> form->getFieldset($name) as $field) : ?> label; ?> input; ?>

That should help you get the job done. Now, add the custom fields to Joomla Categories and your custom plugins should now be able to work seamlessly just like other forms. Thanks for stopping by and don’t forget to share our content if you find it helpful, interesting, or worth the read!