Jump to content

Changing subcategory image to differ from Category


Recommended Posts

Hi, I like my category images the way they are, but when I view that certain category, it shows a stupidly small thumbnail at the top which I'd prefer to change to another image to stretch the whole width of the content page.

 

So my question is this (which I have seen done somewhere but can't find where!) I need to know how to edit the relevant tpl files so that I can change the image that shows at the top of each category, instead of showing the thumbnail.

Link to comment
Share on other sites

In category.tpl you normally have the following:

 

<!-- Category image -->
{if $category->id_image}
  <div class="align_center">
<img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" width="{$categorySize.width}" height="{$categorySize.height}" />
  </div>
  {/if}

 

You only get one image per category (though there can be multiple resized versions) so short of a custom module or class override, you would have to create custom images in a known location following a predictable naming format that you can reference in the template.

 

Something like . . .

 

		<!-- Category image -->
		<div class="align_center">
			<img src="http://example.com/path/to/images/{$category->name|regex_replace:'/[^A-Za-z0-9]/':'_'}.jpg" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" width="640" height="40" />
		</div>

 

So in the above you are hardcoding the path to the category image to a known location where it is the defined category name but with all non-alphanumeric characters replaced with "_" and a preset height and width 640x40. You may need to also play with the CSS definition if categoryImage has conflicting declarations.

 

Cheers

Edited by codegrunt (see edit history)
Link to comment
Share on other sites

Thanks for the quick reply!

 

Tried the above, still can't get it to load.

 

I set it to <img src="http://www.cleanmitts.org/shop/themes/cleanmittsv1/img/customcat/{$category->name|regex_replace:'/[A-Za-z0-9/':'_'}.jpg"

 

and uploaded the images to that folder... on google chrome debug it's trying to load an image from

 

http://www.cleanmitts.org/shop/themes/cleanmittsv1/img/customcat/.jpg

 

Doesn't look like it's adding the variable - the category name, to the image name.

 

www.cleanmitts.org/shop

Edited by Clean Mitts (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...