Please note: This forum is now closed. All the support related enquiries should be reported on wordpress support forum for jigoshop plugin – thanks, Jigoshop Team

Category image is not showing on frontend

treebeard's Avatar

treebeard

27 Sep, 2012 10:45 AM

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?

  1. 1 Posted by Stephen on 08 Oct, 2012 04:11 PM

    Stephen's Avatar

    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:

    <?php
            $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']);
            global $wpdb;
            $mylink = $wpdb->get_row("SELECT * FROM $wpdb->jigoshop_termmeta WHERE jigoshop_term_id = $term->term_id");
            echo wp_get_attachment_image( $mylink->meta_value, 'thumbnail');
    ?>
    

    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 $term get a meta_value in the db table jigoshop_term_id and then use that ID to get attachement image using existing WP function wp_get_attachment_image.

    Hope it helps you start off!

    Steve

  2. 2 Posted by treebeard on 08 Oct, 2012 11:45 PM

    treebeard's Avatar

    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?

  3. 3 Posted by Stephen on 09 Oct, 2012 08:17 AM

    Stephen's Avatar

    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...

    ?php get_header('shop'); ?>
    
    <?php do_action('jigoshop_before_main_content'); // <div id="container"><div id="content" role="main"> ?>
    
        <?php
            $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']);
    

    After that code you can insert the following code...

    $default_attr = array(
                'class' => "alignleft",
                'alt'   => "",
                'title' => wptexturize($term->name),
            );
            global $wpdb;
            $cat_thumb = $wpdb->get_row("SELECT * FROM $wpdb->jigoshop_termmeta WHERE jigoshop_term_id = $term->term_id");
            if($cat_thumb) echo wp_get_attachment_image( $cat_thumb->meta_value, 'thumbnail',0,$default_attr);
    

    (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....

  4. 4 Posted by treebeard on 09 Oct, 2012 08:55 AM

    treebeard's Avatar

    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?

  5. 5 Posted by treebeard on 09 Oct, 2012 09:04 AM

    treebeard's Avatar

    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.

  6. 6 Posted by Stephen on 12 Oct, 2012 01:36 PM

    Stephen's Avatar

    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...

    $mylink = $wpdb->get_row("SELECT * FROM $wpdb->jigoshop_termmeta WHERE jigoshop_term_id = $term->term_id AND meta_key = 'thumbnail_id'");
    

    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!!

  7. 7 Posted by treebeard on 13 Oct, 2012 07:44 AM

    treebeard's Avatar

    IT WORKS!!! ha! thank you so much for your help!! I tried with one of the categories, and the size is even correct... awesome!!!

  8. 8 Posted by Stephen on 15 Oct, 2012 03:38 PM

    Stephen's Avatar

    Glad I could help out! BTW - another update to my now rubbish initial code is as follows:

    if($cat_thumb->meta_value!-'') echo wp_get_attachment_image( $cat_thumb->meta_value, 'thumbnail',0,$default_attr);
    

    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!!

  9. 9 Posted by Stephen on 15 Oct, 2012 04:00 PM

    Stephen's Avatar

    typo - $cat_thumb->meta_value!=''

  10. 10 Posted by humblegiants on 19 Oct, 2012 08:50 PM

    humblegiants's Avatar

    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

  11. 11 Posted by humblegiants on 19 Oct, 2012 09:11 PM

    humblegiants's Avatar

    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(

            'alt'   => "",
            'title' => wptexturize($term->name),
            );
    
        global $wpdb;
        $mylink = $wpdb->get_row("SELECT * FROM $wpdb->jigoshop_termmeta WHERE jigoshop_term_id = $term->term_id AND meta_key = 'thumbnail_id'");
        if($cat_thumb) echo wp_get_attachment_image( $cat_thumb->meta_value, 'large', 0, $default_attr);
    
        echo wp_get_attachment_image( 3711, 'full');
    
  12. 12 Posted by humblegiants on 19 Oct, 2012 10:59 PM

    humblegiants's Avatar

    AH! Yes! got it working. took a break and saw my error. durrrr

    thanks again!

  13. 13 Posted by Stephen on 19 Oct, 2012 11:07 PM

    Stephen's Avatar

    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 as if($cat_thumb) has not been defined, so your echo will not.. echo. Echoing wp_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 your 3711 with the dynamic ID, which just so happens to equal $cat_thumb->meta_value.

    So after global $wpdb; you need the following:

    $cat_thumb = $wpdb->get_row("SELECT * FROM $wpdb->jigoshop_termmeta WHERE jigoshop_term_id = $term->term_id AND meta_key = 'thumbnail_id'");
    if($cat_thumb->meta_value!-'') echo wp_get_attachment_image( $cat_thumb->meta_value, 'large');
    

    Scrap your last line with the wp_get_attachement_image and the 3711 ID. And change the large in the code above to either thumbnail, medium, large or full to echo out the size you need (set in the WP Admin Settings->Media).

    Hope that makes sense!

  14. 14 Posted by Stephen on 19 Oct, 2012 11:09 PM

    Stephen's Avatar

    ahh, I type, you drink coffee! Glad you spotted it, hope my answer was what you figured out!

    Nighty night! Steve

  15. 15 Posted by sahil on 30 Oct, 2012 06:30 AM

    sahil's Avatar
  16. 16 Posted by humblegiants on 28 Nov, 2012 04:29 AM

    humblegiants's Avatar

    Yep! your code & mine were exactly the same Stephen. thanks again for the help. :)

  17. 17 Posted by Jerry on 05 Dec, 2012 02:39 AM

    Jerry's Avatar

    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?

  18. 18 Posted by Stephen on 06 Dec, 2012 10:42 AM

    Stephen's Avatar

    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

  19. 19 Posted by Jamers on 11 Jan, 2013 03:19 PM

    Jamers's Avatar

    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....

  20. 20 Posted by kg on 13 Jan, 2013 03:52 AM

    kg's Avatar

    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 $term = get_term_by( 'slug', get_query_var($wp_query->query_vars['taxonomy']), $wp_query->query_vars['taxonomy']); 
                        $default_attr = array(
                            'class' => "alignleft",
                                'alt'   => "",
                             'title' => wptexturize($term->name),
                            );
                            global $wpdb;
                        $cat_thumb = $wpdb->get_row("SELECT * FROM $wpdb->jigoshop_termmeta WHERE jigoshop_term_id = $term->term_id AND meta_key = 'thumbnail_id'");
                        if($cat_thumb->meta_value!='') echo wp_get_attachment_image( $cat_thumb->meta_value, 'large');  
    ?>
    
    
    <h1 class="page-title"><?php echo wptexturize($term->name); ?></h1>
    
    <?php echo wpautop(wptexturize($term->description)); ?>
    
    <?php jigoshop_get_template_part( 'loop', 'shop' ); ?>
    
    <?php do_action('jigoshop_pagination'); ?>
    

    <?php do_action('jigoshop_after_main_content'); //

    ?>

    Any ideas?

  21. 21 Posted by MYL on 25 Feb, 2013 08:02 PM

    MYL's Avatar

    Hi,
    I tried but it doesn't work. Can I find the complete php file anywhere?
    Thanks,
    MYL

  22. 22 Posted by Andy on 24 Aug, 2013 12:16 AM

    Andy's Avatar

    or do what I did buy it for $5.00 instead of the $30.00, works great and this should have been a standard feature
    http://www.oscanyon.com/products/jigoshop-category-image-plugin/

  23. 23 Posted by Andy on 24 Aug, 2013 12:19 AM

    Andy's Avatar

    or do as I did and get it for $5.00 not $30.00 here
    http://www.oscanyon.com/products/jigoshop-category-image-plugin/
    made by someone else not the author of JigoShop
    I did post but the page went blank so maybe something is not right on here?
    http://www.oscanyon.com/products/jigoshop-category-image-plugin/

  24. 24 Posted by Etienne Cauchi on 30 Aug, 2013 09:26 AM

    Etienne Cauchi's Avatar

    I have just bought this plugin but it will not work with wordpress. I asked for support but they did not even replied back.

  25. 25 Posted by Andy on 30 Aug, 2013 02:55 PM

    Andy's Avatar

    @ Etienne Cauchi
    you are LIAR, you DID NOT BUY this plugin, the Jigoshop plugin works perfectly

  26. 26 Posted by Powderflask on 30 Dec, 2013 08:57 PM

    Powderflask's Avatar

    Update:
    There appears to be a jigoshop function to get the term image id - MUCH preferable to making a raw SQL request. Try something like:

        $thumb = jigoshop_product_cat_image( $term->term_id );
        if ( $thumb['thumb_id'] )
            $thumb_image = wp_get_attachment_image( $thumb['thumb_id'], 'thumb' );
    
    hope that helps.

Comments are closed, but you can start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac