简体   繁体   English

Joomla 2.5:向文章添加自定义图像参数

[英]Joomla 2.5: Adding a custom image parameter to an article

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: 我通过在本节顶部添加以下字段来修改/administrator/components/com_content/models/forms/article.xml文件:

<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): 我将此代码添加到主题的com_content / article / default.php页面(在if($ params-> get('show_title'))块内部):

<?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? 我是Joomla的新手,所以这很明显,但是我想念什么?

Thanks! 谢谢!

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. 在2.5版中,已经有一个标准化的图像字段(实际上是2个),您要做的就是覆盖布局以将图像放置在所需的位置。

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. 如果您已经使用了两个下摆,我将修改图像字段以添加第三张图像。

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 . 首先,您需要确保将字段添加到article.xml中的特定位置。 I would suggest adding it before or after <field name="show_title"> on line 127 我建议在第127行的<field name="show_title">之前或之后添加它

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 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM