0
votes

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!

2
At the end of the day, what I am doing here works - once I add one small character. For some reason the computer can't tell that when I type this: $this->params-> , I obviously mean this: $this->$params-> Sometimes I hate programming.JeffW

2 Answers

1
votes

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.

0
votes

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