Reputation: 186
I want to be able to add an image next to the title of an article (and be able to select the image for each article - not just a one and done setting). I modified the /administrator/components/com_content/models/forms/article.xml file by adding these fields at the top of the section:
<field
name="titleImage"
type="media"
label="Title Image"
description="Image that will be displayed next to the article's title." />
<field
name="spacer0"
type="spacer"
hr="true"
/>
This adds the parameter to the Edit Article page and lets me select an image.
I added this code to my theme's com_content/article/default.php page (inside the if ($params->get('show_title')) block):
<?php if($this->params->get('titleImage')){ ?>
<img class="titleImage" src="<?php echo htmlspecialchars($images->titleImage); ?>" alt="Title Image" />
<?php } ?>
The image is not appearing on the page. I'm new to Joomla so it may be obvious, but what am I missing?
Thanks!
Upvotes: 0
Views: 1465
Reputation: 6770
In 2.5 there is already a standardized image field (actually 2) and all you have to really do is make a layout override to put the images where you want them.
YOu should modify the form using a plugin if you go that route. I would modify the image field to add a third image if you are already using the two of hem.
Upvotes: 1
Reputation: 19733
After some testing I found out why it wasn't working:
Firstly, you need to ensure you add the field to a specific place in article.xml. I would suggest adding it before or after <field name="show_title">
on line 127
Then, you can call the parameter like so:
<?php if ($params->get('titleImage')) : ?>
<img class="titleImage" src="<?php echo JURI::root() . $params->get('titleImage'); ?>" alt="Title Image" />
<?php endif; ?>
Hope this helps
Upvotes: 0