Skip to content

How to add additional field in the Joomla article administrator page

To add custom article submission field:

Files needed to edit:
i.      jos_content table in joomla database
ii.     root/components/com_content/views/article/tmpl/default.php
iii.    root/components/com_content/views/article/tmpl/form.php
iv.     root/administrator/components/com_content/models/article.xml
v.      root/administrator/components/admin.content.html.php
vi.     root/administrator/components/config.xml
vii.    root/libraries/joomla/database/table/content.php

1.      jos_content table update

1.1.    Open up phpMyAdmin or your respective mysql database editor
1.1.i.  If you’re working on your local server
1.1.i.a.        Copy this link in you’re browser window http://localhost/phpmyadmin/index.php
1.1.i.b.        If you have a lamp set up with xampp open the control panel a
click on admin on the apache row and click on phpMyAdmin
1.2.    Choose the respective database for the needed Joomla installation
1.3.    Open the jos_content table
1.4.    Click on structure
1.5.    Scroll add form and add rows with the name of the custom fields
you will be adding

2.      default.php
2.1.    Open “root/components/com_content/views/article/tmpl/default.php”
2.2.    Scroll to line 25 and insert the following code replace
“custom_field” with the name of its corresponding row in the
jos_content table:

<?php echo $this->escape($this->article-> custom_field); ?>

2.3.    If you will be adding parameters to the field (i.e.: show
custom_field, link custom_field, etc..) use the following code:

<?php if ($this->params->get(‘show_ custom_field ‘)) : ?>

<sub width=”100%”>
<?php if ($this->params->get(‘link_ custom_field ‘) && $this-

>article->readmore_link != ”) : ?>

<a href=”<?php echo $this->article->readmore_link; ?>”
>
<?php echo $this->escape($this->article-> custom_field); ?></a>
<?php else : ?>
<?php echo $this->escape($this->article-> custom_field); ?>
<?php endif; ?>
</sub>
<?php endif; ?>

3.      form.php
3.1.    Let’s add our field to the front end submission form!
3.2.    Open root/components/com_content/views/article/tmpl/form.php
3.3.    Scroll to line 79
3.4.    Insert <label> and <input> fields
3.4.i.  Label Code:

<label for=”title”>
<?php echo JText::_( ‘custom_field ‘ ); ?>:
</label>

3.4.i.a.        Replace “custom_field” with the text you would like to appear
on the submission form screen.
3.4.i.b.        This code renders the label text next to the field box
3.4.ii. Input Code

<input type=”text” id=” custom_field ” name=”
custom_field ” size=”50″ maxlength=”100″ value=”<?php echo $this-

>escape($this->article-> custom_field); ?>” />

3.4.ii.a.               Replace “custom_field” with the name of its corresponding
row in the “jos_content” table
3.4.ii.b.       This code will render the text field for user entry

4.      article.xml
4.1.    Follow these intructions if you’d like to add parameters to
control the visibility and/or linkability of your field. And you can
disseminate these instructions to add more parameters.
4.2.    Open root/administrator/components/com_content/models/article.xml
4.3.    Scroll to line 27
4.4.    To add a parameter to choose whether or not your field will be
visible on the front page add this code:

<param name=”show_ custom_field ” type=”list” default=”” label=”Show
custom_field ” description=”Show/Hide the articles subtitle”>
<option value=””>Use Global</option>
<option value=”0″>No</option>
<option value=”1″>Yes</option>
</param>

4.4.i.  Replace “custom_field” with the name its corresponding row in
the jos_content table
4.4.ii. The “name” field must match the variable used in the
default.php to evaluate whether or not this parameter is set.

To add a parameter to make the field linkable to the current article
insert the following code:

<param name=”link_ custom_field” type=”list” default=”” label=”Linked
custom_field ” description=”TIPIFYESTITLECONTENTITEMS”>
<option value=””>Use Global</option>
<option value=”0″>No</option>
<option value=”1″>Yes</option>
</param>

4.4.iii.        Replace “custom_field” with the name its corresponding row in
the jos_content table
4.4.iv. The “name” field must match the variable used in the
default.php to evaluate whether or not this parameter is set.
4.5.    Both above codes render in the article editing view in the
administrator Backend

5.      admin.content.html.php
5.1.    Open root/administrator/components/admin.content.html.php
5.2.    Scroll to line 797 (Just after the <tr> that contains <?php echo
$lists[‘state’]; ?>
5.3.    Insert the following code:

<tr>
<td>
<label for=” custom_field “>
<?php echo JText::_( ‘ custom_field ‘ ); ?>
</label>
</td>
<td>
<input type=”text” name=” custom_field ” id=”
custom_field ” size=”40″ maxlength=”255″ value=”<?php echo $row->
custom_field; ?>” />
</td>
</tr>

5.3.i.  Replace “custom_field” with the label used for its
corresponding row in the jos_content table.
5.3.ii. This code will create a new row just below the “title” field
on the article submission form in the administrator backend.

6.      config.xml
6.1.    The following will add parameters to the article manager page
parameter list
6.2.    Open “root/administrator/components/config.xml”
6.3.    Scroll to line 16 and insert:

<param name=”show_subtitle” type=”radio” default=”1″ label=”Show
Article SubTitle” description=”Show/Hide the articles subtitle”>
<option value=”0″>No</option>
<option value=”1″>Yes</option>
</param>
<param name=”link_subtitles” type=”radio” default=”1″ label=”Linked
SubTitles” description=”TIPIFYESTITLECONTENTITEMS”>
<option value=”0″>No</option>
<option value=”1″>Yes</option>
</param>

6.3.i.  The top <param> is the parameter defining whether the field
will be visible on the front end
6.3.ii. The bottom <param> defines whether the field is a link
6.3.iii.        Compare with previous xml edit.

7.      Content.php
7.1.    Open “root/libraries/joomla/database/table/content.php”
7.2.    Scroll to line 33
7.3.    Insert:

var $subtitle   = null;
/** @var string */

8.      Extra notes
8.1.    Steps 1,2,3, and 5 must be completed for a field to appear in the
submission forms(both front and back), and render on the front end.
8.2.    Steps 4 and 6 are parameter creations that add extra control over
the fields.
8.3.    To add the custom fields to the Section and Category view add:

<?php echo $this->escape($this->this-> custom_field); ?>

to the proper location and follow the page convention.

8.3.i.  Insert in section/tmpl/blog_item.php line 25
8.3.ii. Add to section query compnents/com_content/models/section.php
line 414
8.3.iii.        “a.subtitle”
8.3.iv. Add module query models/category/php line 361
8.3.v.  “a.subtitle”
8.4.    The parameters for section and category blog and list view can be
inserted in the same manner as the article parameters above.  Find the
proper xml file and add parameters for the custom field!

Original article by Dan “Diggler” Proczko from http://groups.google.com/group/joomlagrandrapids/browse_thread/thread/10d2610576fadab5?pli=1

Published inCoding

14 Comments

  1. web reviews

    Nice informative article… I am trying to build a large site [something like directory] but dont like to use any existing directory component becuase of too many mysql call… so looking for something to add custom field on content.. this is very good article who like to build a large site with high perfomance.

  2. web reviews

    on line 5.1. Open root/administrator/components/admin.content.html.php it should be root/administrator/components/com_content/admin.content.html.php

  3. Anonymous

    In the config.xml. I think the word “subtitle” should be changed to the “custom_field” name, if you want to control the article parameters for all the articles globally.
    I am no expert, but that´s what worked for me.
    Thanks for the article and kind regards Sixten

  4. Daniel "Diggler" Proczko

    That’s awesome! My article made it all the way to this site! Be sure to check back to my blog (http://www.apt2labs.com/apt-notebook) for more blog posts.
    “Diakuyu” (Ukrainian for “Thank You”)

  5. Mauricio

    Hi There,
    Thanks for the post really really helpfull, would you know how to instead of adding a input I could add an editor field?
    I managed to add it comes up fine, saves the text fine but when I apply any paragraph style or insert an image it does not same the tags. Just save the plain text.
    Any Idea?
    Many thanks.

  6. Gamer-t

    ty man for this tuto very helpfull.
    Many thanks.

  7. Md. Mehedi Hasan

    Nice Tips Man. I’ll try this one

  8. Irfan

    Not working with joomla 1.6,
    can anybody provide help regarding this

  9. Jeffrey

    Hi,

    I really hope someone reads this. I do not have the admin.content.html.php file in the com_content map that is located in administrator. And I can’t find it elsewhere. Do you have any idea how it’s called or where it is?

  10. Danny

    Bad IDEA, BAD bad Idea.
    what if you upgrade joomla ? do you have to do all these steps again?
    I also am looking for a better solution that doesn’t require to edit joomla core files.

  11. david

    very helpfull.
    Many thanks.

  12. hhgh

    Where is the location of the following items in joomla 2.5 and 3
    Files needed to edit:
    i. jos_content table in joomla database
    ii. root/components/com_content/views/article/tmpl/default.php
    iii. root/components/com_content/views/article/tmpl/form.php
    iv. root/administrator/components/com_content/models/article.xml
    v. root/administrator/components/admin.content.html.php
    vi. root/administrator/components/config.xml
    vii. root/libraries/joomla/database/table/content.php

  13. hhgh

    please update this article for joomla2.5 and joomla 3.3

Leave a Reply

Your email address will not be published. Required fields are marked *

*