Recently I had the chance to work with the latest version of Joomla in a multi-language project. Having used a custom made language tool before, I felt Joomla’s built in design was poor for handling content editing for multiple languages. Fortunately, however, the solution was simple. The solution is to modify the way the articles work so that we can have extra content fields, each corresponding to a different language. While I found instructions on modifying Joomla 1.5, there was little to no documentation on modifying 1.7 this way. Fortunatelly however, at least half of the process is very similar, furthermore, Joomla 1.7’s core code is organized enough that making any modifications feels more natural than it tends to be with other software. So this is how I got 1.7 to allow me to have extra fields. This will surely make Joomla a lot more flexible

So in this tutorial I will cover how to add new fields to your articles, how to link them to the database, and how to modify the output of your modules and components so that you can achieve the results desired.

Adding a custom field

1. Go to administrator\components\com_content\models\forms\article.xml
In it you’ll find a list of field tags in xml. These are the fields that make the forms you see when you edit an article.
1
2
3
4
5
<field name="articletext" type="editor" class="inputbox"

label="COM_CONTENT_FIELD_ARTICLETEXT_LABEL" description="COM_CONTENT_FIELD_ARTICLETEXT_DESC"

filter="ContentHelper::filterText" buttons="true" />
You can copy and paste that, but make sure to change the name attribute to something else, preferably something which describes your textbox. Maybe you want to use it to be the text for a different language.
1
2
3
4
5
<field name="japaneseText" type="editor" class="inputbox"

label="COM_CONTENT_FIELD_ARTICLETEXT_LABEL" description="COM_CONTENT_FIELD_ARTICLETEXT_DESC"

filter="ContentHelper::filterText" buttons="true" />
In the example above I am creating a field which I will use to put Japanese text
2. Now that we added the fields to our admin model, lets add it to the view so we can see it on our admin Interface. For this, go to administrator\components\com_content\views\article\tmpl\edit.php (we can use these folder and file names for an override)
You can write changes here or override them while keeping the original. To do an override we use the same folder names but place them in our administrator template.
You can find out which admin template you are using by logging in to your joomla website, and going into extensions > template manager.
Joomla Template Manager
Below the area on the above image, in the template manager screen you should see a list of all your templates, as well as an indicator for that which is being used as your administration template.

Overriding the template : Skip these steps if you will be making changes straight into the core components. Overriding, however is a much safer approach as you’ll keep your original should any changes arise.

* go to administrator\components\com_content\views\article\tmpl\edit.php and copy the edit.php file

*now go to administrator\templates\yourtemplate\html\

If the html folder indicated above does not exist then add it.

Also add the folders below if they are not there already

com_content\ article\edit.php (this is the php you copied from the components folder, and here you are overriding it. It’s the same as changing the original, but its good to keep the original intact in case the need to revert ever arises. )

3. Editing the Edit.php file
In the edit.php file you will see these lines that output an input field called articletext.
1
2
3
4
<div class="clr"></div>
<?php echo $this->form->getLabel('articletext'); ?>
<div class="clr"></div>
<?php echo $this->form->getInput('articletext'); ?>
If you look at the xml file in the first step you will see the field we copied had that same name. With that said you can also copy this same code, but instead of using articletext as the name, use the name of your new textbox.
1
2
3
4
5
6
7
8
9
10
11
//Our new textbox
<div class="clr"></div>
<label>Article Text - Japanese Text</label>
<div class="clr"></div>
<?php echo $this->form->getInput('japaneseText'); ?>

//The default textbox
<div class="clr"></div>
<?php echo $this->form->getLabel('articletext'); ?>
<div class="clr"></div>
<?php echo $this->form->getInput('articletext'); ?>
I had called my textbox japaneseText, and you can see I copied the getInput code and used JapaneseText as the argument above. I am hardcoding the label in this case, as Article Text – Japanese Text
Now we have a new textbox on the administration end. This is how it looks now when we go to add a new article.
our custom Joomla field
4. Hooking up our new textbox with the database.
Although the textbox now exists, it is not hooked up to the database. In your database, in your content table called yourPrefiX_content we need to add a new field with the same name you used for your textbox in the xml file (in my case japaneseText)
You can add this new field through php my admin or using this command
1
ALTER TABLE ` yourPrefiX_content ` ADD `japaneseText` VARCHAR( 255 ) NOT NULL;
You may use mediumText instead of varchar(255)
If the command executed successfuly our new input field should now be writing to our database.

So this is all for the admin end. Next post this week I will write part 2 of “Add custom content fields to Joomla.” In part 2 I will cover how to output these textfields in your website, as well as some tricks for Joomla using some of the techniques covered in the two articles.

Edits (Some comments include additions many may find helpful) Edited

Alex commented on how to display the custom fields in the frontend submission form

  • To display the custom fields in frontend submission form, do these above edits (1 to 3) in
  • /components/com_content/models/forms/article.xml
  • components/com_content/views/form/tmpl/edit.php (you may want to copy this file to your template.

I look forward to reading any questions or suggestions you may have

Share this:

Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter
If you enjoyed this post, make sure you subscribe to my RSS feed!

Comments RSS and TrackBack Identifier URI ?
Do you want to comment?

30 responses

Kelio

Nice article.

very useful
thanks you very much

i can’t wait to read the second part !

August 26, 2011 6:58 am

Robert

I’ve googled long time. Thanks for your work. Waiting hard for part 2.:-)
Great blog!

August 26, 2011 12:44 pm

Chris

Great little article… also looking forward to pt2.

Would be interested to see a follow-up showing different fields for different categories 🙂

August 28, 2011 2:20 am

Andres Gallo

Part II of the is up. Enjoy, and don’t forget to leave me some feedback and suggestions. Hope to be writing more often.

August 28, 2011 7:51 pm

Andres Gallo

hey Chris, I did not exactly include an example with different categories, however, I did include an example on showing different fields for different languages. You can modify that if statement to check for specific categories. I hope that is helpful

August 28, 2011 7:56 pm

diablo 3 gameplay

Everything is quite open and really clear explanation of troubles. was truly data. Your internet site is quite useful. Many thanks for sharing.

September 11, 2011 5:54 pm

shiva

well explained

September 27, 2011 7:02 am

Ghego1

First, thank’s so much for this article, it is so usefull!!!!!
Sorry for the probably silly question, but I’m having really big troubles editing the “yourPrefiX_content” table… How do I do that? I went on the phpadmin page but I couldn’t find it (I assume it should be the jos_content table).
And I have no idea of how to use the command line you provided… Sorry, again, but I have little/no competences on MySql…

October 15, 2011 12:27 pm

Ghego1

Solved! Apparently it was a problem with Bitnami, so I reinstalled everything using Xampp and now through phpmyadmin I’ve set all the parameters needed. My sugestion, avoid Bitnami!

October 16, 2011 5:51 am

Andres Gallo

I’m glad you solved it. I am sorry not to have replied earlier. I was having a blog vacation hehe

October 22, 2011 6:38 pm

Jose

Tremendooo llevabaa mucho tiempo buscando una solución y tu me la has dado .
He añadido un nuevo campo Fecha gracias a ti , ahora solo me hace falta poder ordenar los articulos por ese campo

November 30, 2011 12:14 pm

Andres Gallo

Que bien. Voy a empezar unos tutoriales tambien en javascript. Espero que vos continues leyendo.

Gracias

December 7, 2011 8:51 pm

jayendra

Thanks. I was searching this but did not find any solution. I hope, it will solve my problem.

December 19, 2011 8:25 am

alex

Hi,

Thank you for this..

To display the custom fields in frontend submission form, do these above edits (1 to 3) in
(1) /components/com_content/models/forms/article.xml (
2) components/com_content/views/form/tmpl/edit.php (you may want to copy this file to your template.

January 18, 2012 8:11 am

proyecto

Very nice article. Thank you. Joomla is turning me mad.

February 23, 2012 3:16 am

bhargavi

Hi geeks, Can anybody out there help me in knowing: How to add custom content fields to joomla articles?

March 21, 2012 1:32 am


Meisam

You Save me Boy! Very Usefull

September 12, 2012 2:02 am

Markus

Hello,

great Tutorial. But not all files can be override by own template. The problem: After Joomla Update 2.5.7 the files will override and nothing works.

October 26, 2012 4:46 am

Hoai Bao

I have been searching for long time on this and thanks for your great article.

HB.

January 30, 2013 1:41 am

Andreas

Crap! Never overwrite core files!

March 8, 2013 7:24 am

Uzair

Thank you. This very well served it purpose, but the very same field is not visible when we edit/update the same article. I’d really like to know how can we achieve it.

May 20, 2013 6:35 am

sateesh

Thanx a lot… its Perfectly working… but I want same documentation in joomla 1.5 version. Because Its not working in joomla 1.5 version. Please help me

May 24, 2013 2:55 am


jorge

hi I need to add a field with multiple dates, I think, a dates array. For example if an event is in more than one day. 1, 2 , 6 , 8 of july 2013 for example.

June 13, 2013 1:05 pm

webadmin

Hey Thanks For It !!

You saved my life 🙂

July 5, 2013 5:43 am

Antonella

Andres, thank you very much 🙂 You’ve been a great help to me.

October 27, 2013 8:52 am


Stefan

Hello,

great article. Very helpfull.

But got here an error. I tryed to make a text-field like this:

I chanched the name and the translationtags. But I can”t get this to workt. I only get the translationtags in transcription. Joomla didn’t translate them. You made it hardcoded too. Is there a solution for this Problem? Joomla 3.3 btw…

August 31, 2016 7:55 am

Andres Gallo

Hi Stefan,

I have not tried this with the 3.3 version, so that may be possibly the issue. I believe I remember seeing some plugins about a year ago that accomplishes this nowadays without the need to modify the application. Please let me know if you find a solution. I can add to the post with your feedback. Thanks man, and sorry not to be able to provide an answer regarding 3.3

September 2, 2016 9:08 am

Comment now!