Adding custom columns/fields to Joomla article, section and user
Table of Contents for Paceville.com - The Coding
- Customizing Joomla 1.5
- Adding AJAX to Joomla 1.5 with jQuery
- Adding custom columns/fields to Joomla article, section and user
- Hardening the Joomla hacks
- Hijacking controllers and views in Joomla
- Search Engine Friendly urls in Joomla
- Facebook style information box with jQuery
- Image manipulation and watermarking in PHP with GD2
- Joomla! 1.5x Customization – Book review and general Joomla discussion
- Mailing with Joomla’s JMail
- Lost Flirts – a Joomla 1.5 component from scratch
- Facebook style photo tagging with jQuery, Ajax and Joomla
- Controlling form tabbing with jQuery
- Facebook style chat with jQuery and Joomla
- JQuery Joomla chat, adding online/offline and friendlist
Run
ALTER TABLE `jos_content` ADD `article_image` VARCHAR( 255 ) NOT NULL
in for instance phpMyAdmin.
Edit administrator/components/com_content/models/article.xml add:
<param name="article_image" type="text" default="" label="Image" description="" />
in the first params section for instance below the access entry.
Add
var $article_image = null;
to libraries/joomla/database/table/content.php
Add
$form->set('article_image', $row->article_image);
to editContent() in administrator/components/com_content/controller.php
The result is that you now have a new field called article_image that can be used in various ways to display a separate image that is not a part of the article, similar to what you have per default for categories and sections.
On an unrelated side note, if custom CSS classes are added to /templates/system/css/editor.css they will appear for selection in tinyMCE. You also need to include it in your template’s index.php, like so:
<link href="templates/system/css/editor.css" rel="stylesheet" type="text/css"/>
That however screwed up my CSS, until I simply commented out everything above STYLES FOR JOOMLA! EDITOR. The end of my editor.css now looks like this:
/*
. . .
div.caption { padding: 0 10px 0 10px; }
div.caption img { border: 1px solid #CCC; }
div.caption p { font-size: .90em; color: #666; text-align: center; }
*/
/* STYLES FOR JOOMLA! EDITOR */
hr#system-readmore { border: red dashed 1px; color: red; }
hr.system-pagebreak { border: gray dashed 1px; color: gray; }
.float_left{ float:left; }
.float_right{ float:right; }
Update: To add fields to the jos_users table in a dirty and quick way as opposed to the proper way:
1.) Add the fields to the jos_users table, for instance firstname.
2.) Add the variables to libraries/joomla/user/user.php and libraries/joomla/database/table/user.php, it has to look like this at the top for instance: var $firstname = null;
3.) Add the input fields to the registration form.
4.) Optionally: In my case I had to override the name field (doesn’t make sense in having a firstname, lastname and name field). In that case I simply added a line to fill the name with firstname and lastname before validation happens (in the register controller, I think the method in question is called register_save()).
Update: I just added a new column to the sections, the point of the new field is to keep track of whether or not we are to show galleries tagged to the section in question when we are in our totally custom blog layout. It was somewhat easier than to the articles, begin with running the following SQL:
ALTER TABLE `jos_sections` ADD `show_galleries` TINYINT( 1 ) NOT NULL
Then add the following HTML to administrator/components/com_sections/admin.sections.html.php add at line 275:
<tr>
<td class="key">
<?php echo 'Show Galleries' ?>:
</td>
<td colspan="2">
<?php echo $lists['show_galleries']; ?>
</td>
</tr>
Add the following PHP to administrator/components/com_sections/admin.sections.php add at line 264:
$lists['show_galleries'] = JHTML::_('select.booleanlist', 'show_galleries', 'class="inputbox"', $row->show_galleries );
Finally, just like with the articles, add this PHP to libraries/joomla/database/table/section.php:
var $show_galleries = null;
Done!
Related Posts
Tags: articles, custom fields, Joomla, sections, tinymce