Add new image field to Joomla 1.7 com_content

試著忘記壹切 提交于 2019-12-08 20:33:31

问题


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?


回答1:


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:

<img src="<?php echo $this->item->addimage; ?>" />

If you store URL link, or

<img src="image/png;base64,<?php echo $this->item->addimage; ?>" />

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)

  1. Firstly create a new column in jos_content table like:

'addimage' varchar(255) DEFAULT NULL

Then modify the following files:

  1. ../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) : ?>

  2. ../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, ' .

  3. ../com_content/models/forms/article.xml [ADD SOMEWHERE]

    <field id="addimage" name="addimage" type="text" label="Add Image" class="inputbox" />

  4. ../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')): ?>




回答2:


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.



来源:https://stackoverflow.com/questions/7747365/add-new-image-field-to-joomla-1-7-com-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!