• Resolved ksolans

    (@ksolans)


    I want to put together a page with a custom template that will display all the Ecommerce WD categories with their image. I’ve found a couple ways to list out all the categories, but I can’t get the image URL.

    I’ve tried using the category ID with wp_get_attachment_image, wp_get_attachment_url and wp_get_attachment_image_src none returned anything.

    This is how I am getting my ID and Category name.

    <?php
    	$categories = get_categories( array(
    		'taxonomy' => 'wde_categories',
        	'orderby' => 'name'
    	) );
    
    	foreach($categories as $c){
    		$cat_id = $c->term_id;
    		$cat_url = esc_url(get_category_link($cat_id));
    		echo '<li><a href="'.$cat_url.'">'.$c->name.'</a></li>';
    	}
    ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello @ksolans!

    Thanks for posting your question!

    Could you please try the following code instead?

    $categories_class = new EcommercewdModelCategories();
    $categories = $categories_class->get_rows(false, array());
    
    foreach($categories as $c){
        $cat_id = $c->id;
        $cat_url = esc_url($c->url);
                $cat_img = $c->image;
        echo '<li><a href="'.$cat_url.'">'.$c->name.'</a></li>';
    }

    Let us know if this works.
    Thank you! Have a wonderful day!

    Thread Starter ksolans

    (@ksolans)

    Thanks for getting back to me so quickly. I gave the provided code a try but with no luck. It is like it didn’t recognize “EcommercewdModelCategories()”. Since this is a standard page using a custom template, could I be missing a call to a script in that template? I haven’t added anything else to the page, so it should be a conflict there.

    Let me know if you want me to post the full template. My site is still just in a local dev stage, so I don’t have a link to share.

    Hi @ksolans!

    Could you please try adding the following to the very beginning of the previous code we posted?

    $controller_path = WD_E_DIR . '/frontend/models/categories.php';
    require_once $controller_path;

    Let me know if this helps.
    Cheers!

    Thread Starter ksolans

    (@ksolans)

    That did the trick, thank you.

    I’m sure I can work it out, but would you also know how to just display the top level (parent) categories?

    Thanks for the help!

    Hi, @ksolans!

    That’s wonderful, we are glad the code worked. You can configure the parent categories to display, but Ecommerce WD itself cannot control this.

    However, you can set this up from WordPress source code. Let me post a few help links, which can be useful for you:

    https://developer.www.ads-software.com/reference/functions/get_terms/
    https://wordpress.stackexchange.com/questions/157818/get-terms-only-top-level

    Let us know in case you have further questions.
    Thanks! Have a wonderful day!

    Thread Starter ksolans

    (@ksolans)

    Thank you again for the follow up. I was able to use an ‘if’ to check for a parent. In case anyone else was trying to do this …

    foreach($categories as $c){
    	if($c->parent == null) {
    	    // My Product Info
    	} 
    }

    Thank you for sharing, @ksolans!

    We are glad you could get the necessary functionality with Ecommerce WD. Please don’t hesitate to open a new thread anytime you will have further questions.

    We’ll be happy to assist!

    If you have a few minutes, please share your rating for Ecommerce WD plugin here. Your feedback will help us improve the quality and features of the product, as well as our customer support service.

    Thank you so much! Have a great day!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Displaying Category Images’ is closed to new replies.