Note!! This is done trough changing some core-files from Joomla. So applying this method will prevent you from updating your version of Joomla because the changed files will probably be overwritten!
Step 1:
Change the database to support the new fields.
Probably using phpMyAdmin, go to the website database (as configured in your Joomla setup), to the table yyy_content (where yyy represents the configured prefix of your joomla setup). Go to "structure", and add the columns to this table.
For my setup i've added the columns "spotlight" of type Boolean, "largeimagesource" of type varchar(512) and "smallimagesource" of type varchar(512).
(Boolean was converted to tinyint(1) by phpMyAdmin)
Step 2
Implement retrieving the data from the database.
Here is where the core hacking begins.
In the following file you need to add the new fields to the SQL-statement.
/components/com_content/models/article.php
In line 84 (approximately) there is a statement
Code: Select all
$query->select($this->getState(...));
For my setup i've changed
Code: Select all
'item.select', 'a.id, a.asset_id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, ' .
Code: Select all
'item.select', 'a.id, a.asset_id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, a.spotlight, a.largeimagesource, a.smallimagesource, ' .
Change the article form definition for front end.
In Joomla 1.7 forms are defined by an XML-file. For an article there are 2 definitions. One for the front end, and one for the back end (the administration part).
First we'll change the front end.
In the following file you need to add the new fields.
/components/com_content/models/forms/article.xml
Somewhere in this XML file you need to add the the new field elements.
Code: Select all
<field
id="[Name of your field]"
name="[Name of your field]"
type="[See below for what types are available for you]"
label="[The text shown in the edit form]"
description="[The text inside the tooltip hovering this field]"
class="[HTML CSS-class of your input element]"
size="[HTML-size of your input element]">
</field>
I've placed them around line 85, just after the "featured" field.
Code: Select all
<field
id="spotlight"
name="spotlight"
type="list"
label="Spotlight"
description="Of dit artikel getoond wordt in de spotlight op de voorpagina."
class="inputbox"
default="0">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
id="smallimagesource"
name="smallimagesource"
type="media"
label="Kleine afbeelding"
description="Kleine afbeelding dat gebruikt wordt op de voorpagina (238*140)."
class="inputbox"
size="50">
</field>
<field
id="largeimagesource"
name="largeimagesource"
type="media"
label="Grote afbeelding"
description="Grote afbeelding dat gebruikt wordt op de voorpagina en boven het artikel(492*140)."
class="inputbox"
size="50">
</field>
Add the fields to the editor in the front end
Now that you've defined the new fields, you have to show them in the editor.
For this you add some elements to the following file:
/components/com_content/views/form/tmpl/edit.php
Somewhere inside you have to add a getLabel and a getInput for you new fields. It is wise to sustain the layout of the editor thus placing it inside a similar container as the other fields.
Find yourself a fieldset and place:
Code: Select all
<div class="formelm">
<?php echo $this->form->getLabel('[Name of your field]'); ?>
<?php echo $this->form->getInput('[Name of your field]'); ?>
</div>
Code: Select all
<fieldset>
<legend><?php echo JText::_('JGLOBAL_FIELD_FEATURED_LABEL'); ?></legend>
<div class="formelm">
<?php echo $this->form->getLabel('featured'); ?>
<?php echo $this->form->getInput('featured'); ?>
</div>
<div class="formelm">
<?php echo $this->form->getLabel('spotlight'); ?>
<?php echo $this->form->getInput('spotlight'); ?>
</div>
<div class="formelm" style="clear:both;">
<?php echo $this->form->getLabel('smallimagesource'); ?>
<?php echo $this->form->getInput('smallimagesource'); ?>
</div>
<div class="formelm" style="clear:both;">
<?php echo $this->form->getLabel('largeimagesource'); ?>
<?php echo $this->form->getInput('largeimagesource'); ?>
</div>
</fieldset>
Change the article form definition for back end.
With finishing step 4 you are able to read and write the new fields through the article-edit functionality directly in the front end side of your website.
I (and i think most other users) edit our articles through the back end side (or the administrator part) of the website.
For this we have to repeat step 3 and 4, for a different part of Joomla.
First we change the form definition of the article. The XML-file for this is found at:
/administrator/components/com_content/models/form/article.xml
Depending on where you want these new fields to be shown, you can find the corresponding fields element inside the XML for where you want to add them.
The elements are defined the same way as in step 3.
I wanted them on the main part of the editor, so I've added these new fields just after "featured" on line 121.
Code: Select all
<field
id="spotlight"
name="spotlight"
type="list"
label="Spotlight"
description="Of dit artikel getoond wordt in de spotlight op de voorpagina."
default="0">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
id="smallimagesource"
name="smallimagesource"
type="media"
label="Kleine afbeelding"
description="Kleine afbeelding dat gebruikt wordt op de voorpagina (238*140)."
size="50">
</field>
<field
id="largeimagesource"
name="largeimagesource"
type="media"
label="Grote afbeelding"
description="Grote afbeelding dat gebruikt wordt op de voorpagina en boven het artikel(492*140)."
size="50">
</field>
Add the fields to the editor in the back end
Final step is to show these new fields in the administrator editor for an article. This is pretty much the same as in step 4, only in a different file.
This file can be found at:
/administrator/components/com_content/views/article/tmpl/edit.php
By reusing the current layout, i've added the following PHP & HTML on line 66, just after the "featured".
Code: Select all
<li><?php echo $this->form->getLabel('spotlight'); ?>
<?php echo $this->form->getInput('spotlight'); ?></li>
<li><?php echo $this->form->getLabel('smallimagesource'); ?>
<?php echo $this->form->getInput('smallimagesource'); ?></li>
<li><?php echo $this->form->getLabel('largeimagesource'); ?>
<?php echo $this->form->getInput('largeimagesource'); ?></li>
That's it.