Joomla 3 and YooTheme Zoo - Use Category Teaser Image For Item Teaser Image

1k Views Asked by At

I have a website built using Joomla 3 and the YooTheme Zoo CCK.

I have created a custom application in my /media/zoo/applications folder.

My Application has two types, Products and Packages.

My packages are divided into categories, and each category has a teaser image set.

I would like to use the "category" teaser image as the teaser image for each "item" within that category.

I am aware of where I should be making the change to my custom application's source code: /media/zoo/applications/my_custom_app/templates/default/renderer/item/teaser.php but I am unsure of the correct line of PHP to add, so that it pulls the teaser image from the category.

I have tried <?php echo $this->category->getImage('content.image'); ?> but it appears that $this->categorydoesn't exists within this context.

Here is a pastebin of my current teaser.php: http://pastebin.com/Pj7UZ4Ye

2

There are 2 best solutions below

0
Alex Bogias On

I can give you a partial answer for what i did in a website i build before. I wanted to display the image of the category on all of the items inside it. I didn't tried to alter the items teaser image but include the image on the existing element category. By default the category element (/media/zoo/elements/itemcategory) can show the category name as a link or just text. So i edited /media/zoo/elements/itemcategory/itemcategory.php at line ~ 40+

public function render($params = array()) {

    $params = $this->app->data->create($params);
    $values = array();
    foreach ($this->_item->getRelatedCategories(true) as $category) {
    +++ $image = $category->getImage('content.teaser_image');
    --- $values[] = $params->get('linked') ? '<a href="'.$this->app->route->category($category).'">'.$category->name.'</a>' : $category->name;
    +++ $values[] = $params->get('linked') ? '<a href="'.$this->app->route->category($category).'"><img src="'.$image['src'].'" title="'.$category->name.'" alt="'.$category->name.'" width="200px" height="200px" />'.$category->name.'</a>' : $category->name;
    }

    return $this->app->element->applySeparators($params->get('separated_by'), $values);
}

So you just remove or comment out what starts with --- and add what starts with +++ You can always override the php file so it will not get updated when you install a new zoo version by copying the file from

/media/zoo/elements/itemcategory/itemcategory.php

to

/media/zoo/applications/products???/elements/itemcategory/itemcategory.php

So you can now edit your application Full layout and remove image and add the categories CORE element to the same position :P

Please let me know if you need any more help!

0
CasperNH On

In case you would like a simple solution to present category Info on item level i hope you will take a look at my custom element for Zoo CCK.

With this element you can place the category image and description in any item. You can read more about the element here: http://www.crea-aalborg.dk/kompetencer/web/joomla-extensions/zoo-elements/category-description.html