Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter dspink

    (@dspink)

    So, not being a programmer I feel like I’m pissing in the wind here.

    I can pull all the category images with the following:

    <?php
    $product_category_terms = get_terms( array(
        'taxonomy'   => "product_cat",
    ));
    
    foreach($product_category_terms as $term){
        woocommerce_subcategory_thumbnail( $term );
    }
    ?>

    But that’s obviously a fat load of good on it own, can you help Daniel?

    Plugin Author Dani Llewellyn

    (@diddledani)

    Hi,

    The solution to this problem is largely similar to the post you linked.

    Copy the template file from wp-content/plugins/a-z-listing/templates/a-z-listing.php into your theme or child theme (using a child theme is preferable if you’re using a theme that you did not create). From there you will need to edit the template to add the function you discovered into an appropriate place. Something like this might work (this isn’t the whole template for brevity; it is amended from the original code from line 52 through to line 61 in the template as shipped in the plugin):

    <?php while ( $a_z_query->have_items() ) : $a_z_query->the_item(); ?>
    	<li>
    		<?php woocommerce_subcategory_thumbnail( $a_z_listing->get_the_item_id() ); ?>
    		<a href="<?php $a_z_query->the_permalink(); ?>">
    			<?php $a_z_query->the_title(); ?>
    		</a>
    	</li>
    <?php endwhile; ?>

    You might want to amend the HTML inside the <li> and </li> tags to allow you to apply a suitable style with CSS. Here is an example with some inline-styles to use flexbox:

    <?php while ( $a_z_query->have_items() ) : $a_z_query->the_item(); ?>
    	<li>
    		<div style="display: flex; flex-direction: row;">
    			<?php woocommerce_subcategory_thumbnail( $a_z_listing->get_the_item_id() ); ?>
    			<a href="<?php $a_z_query->the_permalink(); ?>">
    				<?php $a_z_query->the_title(); ?>
    			</a>
    		</div>
    	</li>
    <?php endwhile; ?>
    Thread Starter dspink

    (@dspink)

    Thanks for the reply and your time Daniel. Unfortunately that creates a fatal error:

    Fatal error
    : Uncaught Error: Call to a member function get_the_item_id() on null in /home/dev/public_html/wp-content/themes/child/a-z-listing.php:57 Stack trace: #0 /home/dev/public_html/wp-content/plugins/a-z-listing/src/Query.php(1201): require() #1 /home/dev/public_html/wp-content/plugins/a-z-listing/src/Query.php(743): A_Z_Listing\_do_template(Object(A_Z_Listing\Query), '/home/dev/publi...') #2 /home/dev/public_html/wp-content/plugins/a-z-listing/src/Query.php(758): A_Z_Listing\Query->the_listing() #3 /home/dev/public_html/wp-content/plugins/a-z-listing/src/Shortcode.php(241): A_Z_Listing\Query->get_the_listing() #4 /home/dev/public_html/wp-includes/shortcodes.php(325): A_Z_Listing\Shortcode->handle(Array, '', 'a-z-listing') #5 [internal function]: do_shortcode_tag(Array) #6 /home/dev/public_html/wp-includes/shortcodes.php(199): preg_replace_callback('/\\[(\\[?)(a\\-z\\-...', 'do_shortcode_ta...', '[a-z-listing ta...') #7 /home/dev/public_html in
    /home/dev/public_html/wp-content/themes/child/a-z-listing.php
    on line
    57

    57 being:

    <?php woocommerce_subcategory_thumbnail ( $a_z_listing->get_the_item_id() ); ?>

    Any further assistance would be most welcome, Darren

    • This reply was modified 5 years, 1 month ago by dspink.
    • This reply was modified 5 years, 1 month ago by dspink.
    • This reply was modified 5 years, 1 month ago by dspink.
    Plugin Author Dani Llewellyn

    (@diddledani)

    Hi, sorry, I made a mistake on the line you highlighted.

    $a_z_listing should be $a_z_query

    Thread Starter dspink

    (@dspink)

    Thanks Daniel

    Error gone but category images aren’t loading, just the placeholder image ??

    https://design-dev.co.uk/wordpress/artists/

    Any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce category images’ is closed to new replies.