Add a new image field in Joomla 1.7 com_content

I'm trying to make some changes to the com_content component of Joomla 1.7. There are not many documents on a specific topic for Joomla 1.7

Maybe you could help me with this.

I want to have a separate field for an additional image in com_content, in particular for Featured view.

As part of the administrator, I managed to add a field - only in html, then in the xml file and, finally, in DB.

Now I am trying to get this entry displayed in my custom html view for Featured Articles.

I just used simple code echo $this->item->addimage; but, unfortunately, it is not displayed.

Any ideas how to achieve this?

Thanks!

And one more thing: as far as I noticed, the structure of component development, database registration, etc. was changed in Joomla 1.7. Any useful link where everything is explained well?

+6
source share
2 answers

Well. If you are sure that your implementation of what you have done is working. i.e. The attached image or just the URL link from the added field is stored in the database, look in the file of the main page /components/com_content/views/featured/tmpl/default_item.php

Here you should put the variable $ this-> item-> addimage, for example:

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

If you keep a URL link or

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

if your image storage is like RAW base64 encoded data


Edit: This should solve your problem if you add your articles from the interface (if the backend, just let me know)

  • First create a new column in the jos_content table, for example:

'addimage' varchar (255) DEFAULT NULL

Then modify the following files:

  • ../com_content/views/featured/tmpl/default_image.php [LINE: 29]

    29: #</h2>

    30: #<?php endif; ?> #<?php endif; ?>

    32: <?php if(!empty($this->item->addimage)): ?>

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

    34: <?php endif; ?> <?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'); ?> #<?php echo $this->form->getInput('created_by_alias'); ?>

    83: #</div>

    85: <div class="formelm">

    86: <?php echo $this->form->getLabel('addimage'); ?> <?php echo $this->form->getLabel('addimage'); ?>

    87: <?php echo $this->form->getInput('addimage'); ?> <?php echo $this->form->getInput('addimage'); ?>

    88: </div>

    90: #<?php if ($this->item->params->get('access-change')): ?>

+1
source

com_content is actually not a way to create the contents of a variable in joomla. It still remains the same inflexible code as mambo. You should try solutions like K2, flexicontent or my favorite ZOO. They are easy to learn, and you can do many cool things with them. Additional fields? No Problem. Some of them already exist for Joomla 1.7 / 2.5. Hacking the kernel is always bad. Mostly because you have lost your upgrade path.

+1
source

Source: https://habr.com/ru/post/899174/


All Articles