Add new image field to Joomla 1.7 com_content
Asked Answered
E

2

6

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?

Elementary answered 12/10, 2011 at 22:33 Comment(7)
Hi Mikey, modifying the core com_content isn't really the best way to go around this. Have you considered a plugin which would allow you to attach an image to an article - I have created 2 extensions which provide very similar functions for 1.5 and the code is mostly transferable to 1.7. Would you be willing to try this as a solution? It would then not be a "core-hack" meaning upgrades to your CMS in the future would not break your modifications.Leeleeann
@Leeleeann thanks for reply, but I guess making a core change is a right option for me right nowElementary
It would appear the same as the way you're currently doing it, if this is what you're worried aboutLeeleeann
I don't believe a core modification is ever the answer. As udjamaflip said, there is a plugin that would do the same thing - I'd strongly recommend going that route. It will save you hours of headache later when you have to upgrade (and you will/should for security purposes!)Appendicle
@Appendicle - What is the plugin name? Just to take a look, maybe I'll like that solution :)Elementary
Ah, sorry Mikey - I was just adding to what udjamaflip had already said... they said they had created 2 extensions that did something similar so they would know the name. Unfortunately I don't - I just know that modifying the core can cause headaches down the road (I know from experience! ugh!)Appendicle
@Mikey I used a combo of plugins and modules to add a meta title to the article manager in Joomla 1.5. The same concept can easily be modified to accommodate your needs. Check here: bit.ly/nAsq9fLeeleeann
P
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')): ?>

Pythian answered 17/10, 2011 at 18:18 Comment(11)
it doesn't get from database at all. I guess I should make the changes in the Models, but unfortunately I didn't find the right place, in the SELECT.Elementary
If you added an appropriate field entry in ../models/forms/article.xml and a column in database take a look at file ../models/article.php and its function &getItem. In a SQL query there is a list of columns in a select clause. Simply add a.addimage to it and you will have $this->item->addimage available.Pythian
Will it be available in Featured articles? It got available inside the article, I'd like to use it in Featured (frontpage)Elementary
Ok, so what view are you using for your frontpage, or what is its full link (not routed)Pythian
I'm using featured view (default_item.php). What do you mean by not routed link?Elementary
OK. Thats fine but I need more instructions like what is the result of the changes I've given you in 2nd commentPythian
It worked fine for the article itself, when you go inside the read more.. but I want it to be displayed on the Featured part, on the front page, I'm using featured viewElementary
Are you sure you are using featured view? Go to Menu Manager: Edit Menu Item and give me the value of "Link" field for your "home" menu item (this is "not routed url")Pythian
Is more likely that you are using "categories blog" or "categories list" than "featured articles" view. If you were using "featured articles" view any changes in "default_item.php" would result in displaying them on the frontpagePythian
when I change anything in the default_item.php it results the changes on the front page, but inserting the echo of $this->item->addimage doesn't have any result.Elementary
I've updated my answer. Should solve the problem if you add your articles in frontend (should you do so on backend just let me know and help you update administration files)Pythian
O
1

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.

Oratorical answered 21/10, 2011 at 21:49 Comment(1)
This is definitely the way to go. Hacking the core when there are extensions that do exactly what you want makes no sense. The changes you would need to make to achieve what you want would be extensive and probably not as well implemented as K2 or Zoo that associate images with articles out of the box.Cockerham

© 2022 - 2024 — McMap. All rights reserved.