Today we will learn how to add more columns/fields to Joomla *_content table. At first we should have to add a column in *_content table.
Run in for instance phpMyAdmin.
ALTER TABLE
jos_content
ADD test
VARCHAR( 255 ) NOT NULL
Edit administrator/components/com_content/models/article.xml add:
In the first params section for instance below the access entry. Add var $test = null;
to libraries/joomla/database/table/content.php
Now add $form->set('test', $row->test);
to editContent()
in administrator/components/com_content/controller.php
The result is that you now have a new field called test that can be used in various ways to display a separate text that is not a part of the article.
Sik
This article is more benefit for me. Hope you post more benefit article in the future. ++
Raj
Hi,
Thanks for your post on Adding custom columns/fields to Joomla article.
I am building a website with Joomla and have beed trying to look for a tool that would allow me to add custom fields
into articles…after looking at various tools I was also thinking of manually adding the field in jos_content … but did not proceed … cause i was concerned whether i would be affecting the other operations in joomla. But since i have seen your post .. i am more convinced to try it out …
Your instructions :
1. “Edit administrator/components/com_content/models/article.xml add:” ( not sure what to add here in article.xml, can you please explain further…)
2. Also would you know whether modifying the *_content table would cause any issues in the other operations of Joomla?
Also it would be a great learning experience if you could tell me why we have to do each of the steps after manually creating the fields … or maybe you can forward a link to some documentation …
Thank you very much.
S.M. Saidur Rahman
Hi
I have attached full process in ppt file and changed file. I think it will be helpful for us.
NB. We have another way to store data in xml file. So don’t need to add field in jos_content table. If anyone feel interest ill write latter.
Download full process
-Rana
SPK
hey rana.
the ppt file helped a lot.
i was able to follow it and add the custom field to myu articles in admin without issue.
so thanks; nice work.
but now i am struggling to use it in my template…
specifically, i want to draw that value in “test” out to the category page that lists articles on my site.
i can modify the html, but am unsure of how to pass the new variable so that i can use it in the template. any help greatly appreciated.
thanks again.
Sitthya
Hi there,
Very smart post! Thank you very much for the effort.
I followed step by step what you write in the ppt but I still have an issue when I save my article, it says :
Unknown column ‘test’ in ‘field list’ SQL=UPDATE
jos_content
SETtitle
=’Arbres et résultats template’,test
=’xcd’,alias
= …Note : I create the coumn ‘test’ through phpmyadmin.
Thank you in advance for your response,
Have a good day.
Philipp
Hi,
Nice post, worked just fine.
I just wondered how I can make use of this field in my frontend template? How can I show the value somewhere?
Thanks in advance!
S.M. Saidur Rahman
Hello Philipp
Thanks for your interest. Ill write soon about that. Stay with me.
-Rana
luke
This is what I am looking for! thanks! MAN
1 thing, I added a custom filed, called “release date”, I wanna it to be displayed on frontpage to replace the “created date”
but seems the new field can not be added to front page.
santanu
Thanks a lot for your help. Its really works for me. But one thing is still not clear how I will display this custom field in the frontend.
please help me in this regd.
Thank you agian…..
santanu
I need help dude..I cant able show those additional fields on the frontend.
Any idea….
Dewa
Adding custom columns to the category list layout
The category list layout now is able to show in the heading the title, date, author and hits. I would like to add a column displaying the content of a custom field I added to my articles, for example ISBN number and the price of a book I wrote an article on.
So I’m able to add custom fields to an article, but I would like these fields to show up in a new column in the category list layout.
Any suggestions on how to do this?
S.M. Saidur Rahman
Hi Dewa,
Just edit bellow files and change commented (bold) lines. Here i take isbn as a extra field for jom_content table.
E:xampphtdocsjoomlacomponentscom_contentmodelscategory.php
function _buildQuery($state = 1)
{
global $mainframe;
// Get the page/component configuration
$params = &$mainframe->getParams();
// If voting is turned on, get voting data as well for the content items
$voting = ContentHelperQuery::buildVotingQuery($params);
// Get the WHERE and ORDER BY clauses for the query
$where = $this->_buildContentWhere($state);
$orderby = $this->_buildContentOrderBy($state);
$query = 'SELECT cc.title AS category, a.id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, a.sectionid, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by,' .
' a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.attribs, a.hits, a.images, a.urls, a.ordering, a.metakey, a.metadesc, a.access,a.isbn,' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'.
' CHAR_LENGTH( a.
fulltext
) AS readmore, u.name AS author, u.usertype, g.name AS groups, u.email as author_email'.$voting['select'] .' FROM #__content AS a' .
' LEFT JOIN #__categories AS cc ON a.catid = cc.id' .
' LEFT JOIN #__users AS u ON u.id = a.created_by' .
' LEFT JOIN #__groups AS g ON a.access = g.id'.
$voting['join'].
$where.
$orderby;
return $query;
}
E:xampphtdocsjoomlacomponentscom_contentviewscategorytmpldefault_items.php
..............................................................
................................................................
....................................................................
<td align="center" class="sectiontableheaderescape($this->params->get('pageclass_sfx')); ?>" width="5%" nowrap="nowrap">
lists['order_Dir'], $this->lists['order'] ); ?>
<td align="center" class="sectiontableheaderescape($this->params->get('pageclass_sfx')); ?>" nowrap="nowrap">
ISBN
.......................................
.............................................
................................................
Please dont forget change colspan value.
If any query just ask me. Best of luck.
–Rana
Wael
Hi
Thank you for the post.
My new field is already in the Backend – and I can add what value I want , however when I publish the article , I have a problem.
I can see the new field in the article view , however I am not able to see it in Category Blog view – where usually I have the articles with “read more”. I cannot see the field there.
Any tips please??
What I did is :
go to:
rootcomponentscom_contentmodelscategory.php
Scroll to about line 361 and add new fields at the following code:
$query = ‘SELECT cc.title AS category, a.id, a.title, ……..
But no results – still cannot see it there.
Help 🙂
S.M. Saidur Rahman
Hi
Have you modify componentscom_contentviewscategorytmpldefault_items.php file? You should have change this file also if you want to see your newly added field in your category list layout. I have explain details in my previous comment. If you need remote support let me know.
-Rana
Sacha
Hi Rana,
It looks like there is a missing line in your article above:
“Edit administrator/components/com_content/models/article.xml add:
?????? <—– nothing shows here!
In the first params section for instance below the access entry."
can you write what is supposed to go in the ??? space for the article.xml document?
thanks for your cool blog,
sacha
Nithin
i added extra field
its showing on article manger – admin view
but not showing user view of article
thanks for your help
max
Hi,
Nice post, I’m working with j1.5.22 and on the backend your customization worked fine.
Wondering how can I show now my new fields on the frontend side. Which php files should be changed to show fields in the article page?
Thanks in advance!
S.M. Saidur Rahman
Hello
E:xampphtdocsjoomlacomponentscom_contentmodelscategory.php
AND
E:xampphtdocsjoomlacomponentscom_contentviewscategorytmpldefault_items.php
Few days ago i have discussed about this, please check (December 14, 2010 at 1:37 PM) Reply. If any further query let me know.
-Rana
sumera
this is not work properly.plz hepl me.
mister mouse
Hi Saidur,
How would you add the custom fields in Joomla 1.6? Your explanation of how to do it for 1.5 was pretty easy but since file structure is different in 1.6 i could figure it out. Thanks
efrab
Hi there great post
But I was wondering does this works for Joomla 1.6?
I am trying this titorial but without any results since some files are just not there in Joomla 1.6….
I would love to add a custom filed like this in Joomla 1.6
Hope you can help….
tugh_man@hotmail.com
Can you tell us how to do this in joomla 1.6 🙁 . thankzs
S.M. Saidur Rahman
Ill write soon.
Thanks
-Rana
Ruben
Dear Rana,
Ik hope you can find some time for Joomla 1.6. Following your tutorial will bring up a custom field in J1.6 also (alternating: administrator/components/com_content/views/article/tmpl/edit.php required), but somehow the field-data won’t load/save.
Thanks in advance!
jai
Hi,
I dont know if some of you have this problem, but my joomla site is so slow when saving an article. i read in internet that maybe is mysql configuration, i had cahnged query_cache size with 64m and key_buffer with 128mb, my server is pentium 4 2.8ghz and 1gb of ram, and still being same thing. so slow, several minutes to save an article.
At somewhere i read that maybe hiding some fields from the listed articles in article manager, could reduce the queries joomla does to show articles after saving or aplying. could you please help me telling me how to hide or delete some fields from showing, like frontend, access and ID? maybe could help me to accelerate the saving time of articles. thanks in dvance!
p.d. i have 13500 articles
tomsky
great article, helped me very much. thanks for it and looking forward to see more
dhananjaya
Hi Saidur,
Please update the ppt for joomla 1.6. it would be of gr8 help to joomla 1.6 users.
Thanks in advance.
-Dhananjaya Kumar
Dhananjay
Hi saidur,
Great article, helped me very much. Much appreciable if the PPT is posted for Joomal 1.6.
Thanks in advance,
Dhananjaya Kumar T.R
uu
Hi There,
Thanks heaps for the nice and clear info. Im on Joomla 2.5 and could you please post instructions to do it on 2.5? Thanks heaps
uds
Hi, Im trying to do this on Joomla 2.5. It dont suport 2.5 isnt it?