添加新的图像字段到 Joomla 1.7 com_content
我正在尝试对 Joomla 1.7 的 com_content 组件进行一些更改 关于 Joomla 1.7 特定主题的文档并不多,
也许你可以帮助我解决这个问题。
我想在 com_content 中为额外图像设置一个单独的字段,特别是精选视图。
在管理员部分,我设法添加该字段 - 仅在 html 中,然后添加到 xml 文件中,最后添加到 DB 中。
现在我正在尝试在我的精选文章的自定义 html 视图中显示该记录。
我只是使用了简单的代码 echo $this->item->addimage;
但不幸的是它没有显示。
有什么想法如何实现这一目标吗?
谢谢!
还有一件事,据我所知,组件开发结构、数据库注册等在 Joomla 1.7 中发生了变化。有什么有用的链接可以很好地解释一切吗?
I'm trying to make some changes to com_content component of Joomla 1.7
There are not many docs on specific topic for Joomla 1.7
Maybe you could help me out on this one.
I want to have a separate field for extra image in com_content, specifically to Featured view.
In the administrator's part I managed to add the field - just in html, then into xml file and finally to DB.
Now I'm trying to get that record displayed in my custom html view for Featured articles.
I just used simple code echo $this->item->addimage;
but unfortunately it's not displayed.
Any ideas how to achieve that?
Thanks!
And one more thing, as far as I have noticed, component development structure, DB registration and so on, has been changed in Joomla 1.7. Any helpful link(s) where everything is explained well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
出色地。如果您确定您所做的事情的实施有效。 IE。您添加的字段中的嵌入图像或简单的 URL 链接存储在数据库中,查看首页文件 /components/com_content/views/featured/tmpl/default_item.php
,您应该将 $this 放置在其中->item->addimage 变量,例如:
如果您存储 URL 链接,或者
如果您将图像存储为 RAW base64 编码数据
编辑:
如果您从前端添加文章(如果是后端,请告诉我),这应该可以解决您的问题。
然后修改以下文件:
../com_content/views/featured/tmpl/default_image.php [LINE: 29]
29:
#
30:<代码>#
32:
item->addimage)): ?>
33:
34:
36:
#get('show_print_icon') || $params->get('show_email_icon') || $canEdit) : ?>
../com_content/models/articles.php [LINE: 160]
160:
# $this->getState(
161:
# 'list.select',
162:
'a.id, a.title, a.alias, a.title_alias, a.introtext, a.addimage, ' .
163:
#'a.checked_out, a.checked_out_time, ' .
../com_content/models/forms/article.xml [添加某处]
<代码><字段
id=“添加图片”
名称=“添加图像”
类型=“文本”
标签=“添加图像”
类=“输入框”
/>
../com_content/views/form/tmpl/edit.php [LINE: 82]
82:
#form->getInput('created_by_alias'); ?>
83:
#
85:
86:
form->getLabel('addimage'); ?>
87:
form->getInput('addimage'); ?>
88:
90:
#item->params->get('access-change')): ?>
Well. If you are sure that your implementation of what you have done works. ie. Embedded image or simply URL link from field you have added are stored in the database have a look into frontpage file /components/com_content/views/featured/tmpl/default_item.php
There you should place your $this->item->addimage variable like:
If you store URL link, or
if your store the image as RAW base64 encoded data
Edit:
This should solve your problem if you add your articles from frontend (if backend, just let me know)
Then modify the following files:
../com_content/views/featured/tmpl/default_image.php [LINE: 29]
29:
#</h2>
30:
#<?php endif; ?>
32:
<?php if(!empty($this->item->addimage)): ?>
33:
<img src="<?php echo $this->item->addimage; ?>" alt="ADDIMAGE" />
34:
<?php endif; ?>
36:
#<?php if ($params->get('show_print_icon') || $params->get('show_email_icon') || $canEdit) : ?>
../com_content/models/articles.php [LINE: 160]
160:
# $this->getState(
161:
# 'list.select',
162:
'a.id, a.title, a.alias, a.title_alias, a.introtext, a.addimage, ' .
163:
#'a.checked_out, a.checked_out_time, ' .
../com_content/models/forms/article.xml [ADD SOMEWHERE]
<field
id="addimage"
name="addimage"
type="text"
label="Add Image"
class="inputbox"
/>
../com_content/views/form/tmpl/edit.php [LINE: 82]
82:
#<?php echo $this->form->getInput('created_by_alias'); ?>
83:
#</div>
85:
<div class="formelm">
86:
<?php echo $this->form->getLabel('addimage'); ?>
87:
<?php echo $this->form->getInput('addimage'); ?>
88:
</div>
90:
#<?php if ($this->item->params->get('access-change')): ?>
com_content 实际上不再是在 joomla 中创建可变内容的方法了。自曼波时代以来,它仍然是同样不灵活的代码。
您应该尝试 K2、flexicontent 或我最喜欢的 ZOO 等解决方案。它们很容易学习,您可以用它们做很多很酷的事情。额外的字段?没问题,其中一些已经存在于 Joomla 1.7/2.5 中。
侵入核心总是不好的。主要是因为你失去了更新路径。
com_content is really not the way for creating variable content in joomla anymore. It's still the same unflexible code since mambo days.
You should try solutions like K2, flexicontent or my favourite ZOO. They are easy to learn and you can do lots of cool stuff with them. Extra Fields? No Proble., Some of them already exist for Joomla 1.7/2.5.
Hacking the core is always bad. Mainly because you loose your update path.