Category image is not showing on frontend
I created a category and added an image for it, but it's not showing on the frontend. I'm assuming there's a chunk of code missing from the default template, does anyone know how to get that to show up?
Log in to Community
I created a category and added an image for it, but it's not showing on the frontend. I'm assuming there's a chunk of code missing from the default template, does anyone know how to get that to show up?
2 Posted by Stephen on 08 Oct, 2012 04:11 PM
Had the same issue, but figured that they probably haven't written it into any templates yet. Have just used the following code which pulls in the category image. Have not set up any error checking or blank images etc, so needs some work - but this should nudge you in the correct direction:
This needs to be put in your category template file (product_taxonomy.php if you are using a basic Jigoshop theme install). It will use the existing
$termget a meta_value in the db tablejigoshop_term_idand then use that ID to get attachement image using existing WP functionwp_get_attachment_image.Hope it helps you start off!
Steve
3 Posted by treebeard on 08 Oct, 2012 11:45 PM
Thanks Stephen, but it's not working :( There's no image showing up on the category page, so not sure what else to do. Have you tried this?
4 Posted by Stephen on 09 Oct, 2012 08:17 AM
Hi treebeard - yeah,. have used the code to implement something on a customer site, which needs the category images to be shown on the cat pages.
Lets strip it back...
You have you theme folder, in that theme folder you have a jigoshop folder. In that jigoshop folder you need a file called
product_taxonomy.php. This is YOUR THEME jigoshop template file to amend/change as you wish. The start of that file should start...After that code you can insert the following code...
(have amended my original code with some more steps as I am tweaking as I am going too!). This should produce your cat image on the cat page.
If not, we need to break down the actions to see what's not working....
Find the post_id number of the image you uploaded as the cat image - to do this, go to Media>Library in WP admin and hover over the image you can see which is you cat image... the URL should give you "attachment_id=XXXX". That is your post_id.
Enter that post_id into the following code:
echo wp_get_attachment_image( XXXX, 'thumbnail');where XXXX is the ID number you have just got. That WILL (should) produce an image on your page the size of your thumbnails set in your WP admin back end.Let me know if that works....
5 Posted by treebeard on 09 Oct, 2012 08:55 AM
hmm, that's weird, because that's exactly how I added the code earlier. Of course, I can't ask the client to go get category ID numbers and edit php code, though. What I'm trying to do is use the Category Image built in to jigoshop, where each category has it's own image. That page in the admin is located under Products > Categories > Edit Category, where you can upload a Category image. It should just grab whatever image is assigned to each category, right?
6 Posted by treebeard on 09 Oct, 2012 09:04 AM
Just realized what you're trying to do. I tried adding the image ID number, and the image shows up but no matter what I set it as in the General Settings > Images, it still comes up as the wrong size. I set the Catalog Image Width as 660 and the height as 314, but it's coming up square, and it's the same size as the other thumbnail images - which by the way is also a number that's not even in the Settings at all, so I don't know where that size is coming from..
ugh.. messy! thanks for taking the time to help me out though.
7 Posted by Stephen on 12 Oct, 2012 01:36 PM
Hi treebeard, if you're still with me - got the same issue you had were the image did not show, needed to make sure the meta value is that for the meta key of thumbnail_id... Use this code instead...
This is still a work in progress on my half, so still swatting bugs!! The issue was that that previous query was pulling other meta date values, not related to the image post id.
This 'should' now work!!
8 Posted by treebeard on 13 Oct, 2012 07:44 AM
IT WORKS!!! ha! thank you so much for your help!! I tried with one of the categories, and the size is even correct... awesome!!!
9 Posted by Stephen on 15 Oct, 2012 03:38 PM
Glad I could help out! BTW - another update to my now rubbish initial code is as follows:
Have amended the check to see if the resultant meta value is valid, as it was always coming back as true... Now it checks to see if the meta_value (i.e.) the tumbnail ID is not blank.
Probably the last amend now!!
10 Posted by Stephen on 15 Oct, 2012 04:00 PM
typo - $cat_thumb->meta_value!=''
11 Posted by humblegiants on 19 Oct, 2012 08:50 PM
Stephen, thanks so much for the code! it works really well, BUT there's 1 hiccup i can't seem to figure out?
Is there any way to automate this? I have a shop with many categories, and having to pull the attachment ID each time seems a bit unwieldy? am I missing something in your code, or is that the only way to make this happen?
thanks so much
12 Posted by humblegiants on 19 Oct, 2012 09:11 PM
btw here is my code, as it is right now. It shows the one specific category image - I KNOW i'm missing something. thanks for any help!
$default_attr = array(
13 Posted by humblegiants on 19 Oct, 2012 10:59 PM
AH! Yes! got it working. took a break and saw my error. durrrr
thanks again!
14 Posted by Stephen on 19 Oct, 2012 11:07 PM
Hi Daniel,
Your code is almost right, but in the last three lines you are dropping the ball...
if($cat_thumb)will always be false asif($cat_thumb)has not been defined, so your echo will not.. echo. Echoingwp_get_attachment_image( 3711, 'full');will always output image ID 3711, as you have found out, so you need to amend your if statement to replace your3711with the dynamic ID, which just so happens to equal$cat_thumb->meta_value.So after
global $wpdb;you need the following:Scrap your last line with the
wp_get_attachement_imageand the3711ID. And change thelargein the code above to eitherthumbnail,medium,largeorfullto echo out the size you need (set in the WP Admin Settings->Media).Hope that makes sense!
15 Posted by Stephen on 19 Oct, 2012 11:09 PM
ahh, I type, you drink coffee! Glad you spotted it, hope my answer was what you figured out!
Nighty night! Steve
16 Posted by sahil on 30 Oct, 2012 06:30 AM
www.ashvi.org
17 Posted by humblegiants on 28 Nov, 2012 04:29 AM
Yep! your code & mine were exactly the same Stephen. thanks again for the help. :)
18 Posted by Jerry on 05 Dec, 2012 02:39 AM
A bit confusing, could you please share the complete final working code? Are you using this in Jigoshop product categories widget or elsewhere? I'm trying to build an opening page that shows all categories with clickable images and category name...is there any other way to do this already?
19 Posted by Stephen on 06 Dec, 2012 10:42 AM
Hi Jerry, the code should work as is. I put mine into a custom page template, but you could also put it into the template file for the shop category page etc. If you want it on the "shop front" you can add the code on the 'archive-product.php' tempalte file in YOUR theme files. Make sure you have the Jigoshop template files in your theme folder. If you are still stuck, reply back and I can paste in a working example code for you.
Steve
20 Posted by Jamers on 11 Jan, 2013 03:19 PM
thanks you so much i will use your code but i dont know change the variable name becoz i am absolute beginners.but you save my job thanks alot buddy keep help people like me....
21 Posted by kg on 13 Jan, 2013 03:52 AM
Hey...so I copied the Shop template and tried to put the code from product_taxonomy.php in there to basically display the category thumbs and can't seem to get it working.
This is the code I copied into the content area of the page template:
<?php do_action('jigoshop_before_main_content'); //
<?php do_action('jigoshop_after_main_content'); //
Any ideas?
22 Posted by MYL on 25 Feb, 2013 08:02 PM
Hi,
I tried but it doesn't work. Can I find the complete php file anywhere?
Thanks,
MYL