Is it possible to use the sub-category thumbnails as a link to the category? So that you can click the thumbnail instead of the text, if yes, can you then also remove the text?
Using Category Thumbnails as Links in Magento
categorylinkthumbnail
Related Solutions
Yes, very possible, and I do exactly the same for a client site.
First I created a new attribute for categories, to allow me to set that a category needs to use the normal link. This is done via a module.
The module structure:
app/code/local/ProxiBlue/AttributeUseNormalFilterLink/
app/code/local/ProxiBlue/AttributeUseNormalFilterLink/Model/Mysql4/
app/code/local/ProxiBlue/AttributeUseNormalFilterLink/etc
app/code/local/ProxiBlue/AttributeUseNormalFilterLink/sql/proxiblue_filterlink_setup
In Model/Mysql4 I have file Setup.php Contents:
class ProxiBlue_AttributeUseNormalFilterLink_Model_Mysql4_Setup extends Mage_Catalog_Model_Resource_Setup {
private $_category_attributes = array(
'use_normal_filter_link' => array(
'label' => 'Use normal filter link in left navigation',
'type' => 'int',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'default' => '0',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'visible_on_front' => true,
'is_visible_on_front' =>true,
'used_in_product_listing' => true,
)
);
public function getDefaultEntities() {
$entities = array();
$default_attribute_options = array(
'group' => 'General Information',
'required' => false,
);
/* Build Catalog Attributes */
$entities['catalog_category'] = array(
'entity_model' => 'catalog/category',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/category',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/category_attribute_collection',
'attributes' => array(),
);
foreach ($this->_category_attributes as $name => $options) {
/* Override values provided by the defaults */
$attribute_options = $default_attribute_options;
foreach ($options as $k => $v) {
$attribute_options[$k] = $v;
}
$entities['catalog_category']['attributes'][$name] = $attribute_options;
}
return $entities;
}
}
in etc folder I have the config.xml contents:
<modules>
<ProxiBlue_AttributeUseNormalFilterLink>
<version>0.0.1</version>
</ProxiBlue_AttributeUseNormalFilterLink>
</modules>
<global>
<models>
<proxiblue_attributeusenormalfilterlink>
<class>ProxiBlue_AttributeUseNormalFilterLink_Model</class>
</proxiblue_attributeusenormalfilterlink>
</models>
<resources>
<proxiblue_filterlink_setup>
<setup>
<module>ProxiBlue_AttributeUseNormalFilterLink</module>
<class>ProxiBlue_AttributeUseNormalFilterLink_Model_Mysql4_Setup</class>
</setup>
</proxiblue_filterlink_setup>
</resources>
</global>
and in the sql fiolder I have the install script : mysql4-install-0.0.1.php contents:
$installer = $this;
$installer->startSetup();
$installer->installEntities();
$installer->endSetup();
Now you can adjust the filter template to use this attribute, and any category can be set to display the actual category link, and not work as a filter.
Copy the template catalog/layer/filter.phtml to your custtom theme folder, then adjust as follows: (note this has some other customization, so pull the bits you need)
<?php $category = false; ?>
<?php if ($this instanceof Mage_Catalog_Block_Layer_Filter_Category): ?>
<?php $category = Mage::registry('current_category'); ?>
<?php if ($category): ?>
<h2>
<a class='level-top' href="<?php $category->getUrl(); ?>"><?php echo $category->getName(); ?></a>
</h2>
<?php endif; ?>
<?php endif; ?>
<ol>
<?php foreach ($this->getItems() as $_item): ?>
<li>
<?php if ($_item->getCount() > 0): ?>
<?php
$link = $_item->getUrl();
if(is_object($category) && !$category->getUseNormalFilterLink()){
$filter = $_item->getFilter();
if($filter instanceof Mage_Catalog_Model_Layer_Filter_Category) {
$linkCategory = mage::getModel('catalog/category')->load($_item->getValue());
if($linkCategory->getId()){
$link = $linkCategory->getUrl();
}
}
}
?>
<a href="<?php echo $this->urlEscape($link) ?>"><?php echo $_item->getLabel() ?></a>
<?php else: echo $_item->getLabel() ?>
<?php endif; ?>
<?php //echo $_item->getCount() ?>
</li>
<?php endforeach ?>
</ol>
You can try like this:
$product->getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail()
Sometimes though you have only one image and want to set all sizes to that same image like so:
if (!$product->hasImage()) continue;
if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
$product->save();
And if you want to see which data you can access in the array:
var_dump(array_keys($product->getData()));
Best Answer
Create a static block with the code:
subcategories
and insert:Create
catalog/category/sub.phtml
Now assign and set whatever root category you want to show its sub categories as their thumbnails with the assigned
subcategories
CMS Block created. Make sure Display mode is set to either Static block only or Products and Static block.Source:
In order to resize the category icons/thumbnails you'll need this:
Resize Category Images:
With the above installed the change to make is: