Last year, I was making an online newspaper with Joomla, and I had to be able to send images as article parameters. Why? Because if you're only able to insert images into the article body, then you're quite handicapped when it comes to placing that images in a newspaper design. I wanted a frontpage where my article image was on top, then my author name and date, and then came the article text. This was not possible when inserting the article image into the article text.

What I found out was, that it's actually quite simple. All you have to do is locate the file: administrator/components/com_content/models/article.xml.

In this file is an XML list with all article parameters. If you want to be able to select an image from your default images/stories directory, then simply put this line into the "Advanced" group:

<params group="advanced">

<!--
This is the line -->

<param name="articleimage" type="imagelist" directory="/images/stories"
hide_default
="1" default="" label="Article Image" description="Image" />

<!-- End of line-->

Now, in your layout files inside of the html folder in your template, you're able to use this parameter to display the image whereever you want to. This is how you get the path to the image:

<?php if ($this->item->params->get('articleimage')) : ?>
<img src="/images/stories/<?=$this->item->params->get('articleimage')?>" />
<?php endif; ?>

It's a neat way to be able to control your images, and remember that you can make as many custom parameters as you want!

Comments (8)
great
1 Monday, 13 July 2009 12:39
fabz
Thanks a lot! I modified your code to have icon in title...quite enough similar to joomla article "Add styling parameters for joomla 15 articles titles" but I can have icon in article and in homepage TOO!
Now I will try to have automatic article field filled based on category (now I have to do manually)...not easy for my knowledge, considering sect and cat have only menu param but that's it!
great II
2 Monday, 13 July 2009 12:52
fabz
PS
I'm not able to write code here, but in the second code I suppose there is a misspelling between stories/ and $this
Kind regards
FabZ
Code correction
3 Thursday, 21 January 2010 11:28
thugsb
On my site using Joomla 1.5.15 I had to use the following code, removing '->item' (replace [] with chevrons):

[?php if ($this->params->get('articleimage')) : ?]
[img src="/images/stories/[?php echo $this->params->get('articleimage'); ?]" /]
[?php endif; ?]
alt
4 Thursday, 21 January 2010 11:31
thugsb
You also may want to include the following code on the second line:
alt="[?php echo $this->escape($this->article->title); ?]"
code clarification
5 Sunday, 28 February 2010 03:51
Cat Ham
I would love this to work. I added the first code in article.xml but am unsure about the second code that needs to be altered ? Added? Where exactly?
I don't know where the"layout files in the html folder in my template" are.
It would be great if someone could clarify. Thank you!
code clarification - Adding image to article header
6 Saturday, 06 March 2010 13:15
Danielle Kinney
This is great. The pull down menu in the Advanced Params. However, I do not know enough to accomplish part 2. What is the path and file name for "item->params->get('articleimage')) : ?>
params->get('articleimage')?>" />
"

Thanks! I am keeping my fingers crossed.
code clarification - Adding image to article header - continued
7 Saturday, 06 March 2010 13:45
Danielle Kinney
OK Found it, for anyone who was wondering..my file was located: templates/yoo_mellow/html/com_content/article/default.php

I added the original information avove and received a page error, then added the 2nd and 3rd pieces from the comments and the page displays but with the following code in the article"[?php if ($this->params->get('articleimage')) : ?] [img src="/images/stories/[?php echo $this->params->get('articleimage'); ?]" /];alt="[?php echo $this->escape($this->article->title); ?]" [?php endif; ?]"

What am I doing wrong?
second part
8 Sunday, 07 March 2010 15:40
Sander
Hey Danielle,

You need to replace all [ and ] with the right character, the chevron character. Google on php tags to see the correct way to write them.

To get the second part working, add it to the following file: components\com_content\views\article\tmpl\default.php just after the canedit var declaration, on the top. This way it'll be displayed above all titles etc.

Add a comment

Your name:
Your email:
Your website:
Subject:
Comment:

Search

Donate

Please consider making a small donation to the development of the Flashfeed extension, this blog and my other Open Source projects. The products are all free and developed in my spare time when I'm not studying. In other words, help me buy pasta and ketchup.