[Resolved] different logo each main category + subcategories

Home Forums Support [Resolved] different logo each main category + subcategories

Home Forums Support different logo each main category + subcategories

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1274951
    Tim

    Hello,

    We made 6 different logo’s for headers using elements for our main categories. This works perfectly. We can select where to show. We have 500 categories in our shop and we would like to the subcategories also show the logo of our main category is this possible in a simple way? selecting all pages is not an option with the amount of categories we use.

    http://www.degros.nl

    Thanks in advance!
    Tim

    #1275660
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    So are there only 6 parent categories which different logos, then 500 sub-categories that should inherit the parent logo?

    Let me know 🙂

    #1275774
    Tim

    Hi Tom

    Yes the parent logo of the particular main category should be set for its subcategories

    Thanks
    Tim

    #1276030
    Tom
    Lead Developer
    Lead Developer

    You may be better off using a function in this case instead of Elements.

    Will these logos apply to all posts within these categories, and the category archives themselves? Or just the archives?

    The logic is likely going to be somewhat complicated, so trying to get a clear picture.

    Thanks!

    #1276248
    Tim

    Hi Tom

    It will apply only for archive categories as products may appear in different categories.

    So for home, product, cart, checkout and normal pages the normal logo should be shown (with 6 dots)

    Thanks
    Tim

    #1276995
    Tom
    Lead Developer
    Lead Developer

    Let’s give it a shot:

    add_filter( 'generate_logo', function( $url ) {
        $category = get_queried_object();
        $category_id = isset( $category->term_id ) ? $category->term_id : '';
    
        if ( is_category( 123 ) || term_is_ancestor_of( 123, $category_id, 'product_cat' ) ) {
            $url = 'URL TO LOGO FOR CATEGORY ID 123 OR CHILDREN';
        }
    
        if ( is_category( 456 ) || term_is_ancestor_of( 456, $category_id, 'product_cat' ) ) {
            $url = 'URL TO LOGO FOR CATEGORY ID 456 OR CHILDREN';
        }
    
        if ( is_category( 789 ) || term_is_ancestor_of( 789, $category_id, 'product_cat' ) ) {
            $url = 'URL TO LOGO FOR CATEGORY ID 789 OR CHILDREN';
        }
    
        // And so on..
    
        return $url;
    } );
    #1278618
    Tim

    Hi tom,

    thanks for this!

    it does not work yet. i did this to test, but nothing happens to the subcategories of this main category:

    https://www.degros.nl/product-categorie/pedicure-groothandel/

    add_filter( ‘generate_logo’, function( $url ) {
    $category = get_queried_object();
    $category_id = isset( $category->term_id ) ? $category->term_id : ”;

    if ( is_category( 311 ) || cat_is_ancestor_of( 311, $category_id ) ) {
    $url = ‘https://www.degros.nl/wp-content/uploads/2020/02/groep-9.svg’;
    }

    return $url;
    } );

    #1279415
    Tom
    Lead Developer
    Lead Developer

    Ah, just updated the code above to work with product categories: https://generatepress.com/forums/topic/different-logo-each-main-category-subcategories/#post-1276995

    #1282244
    Tim

    Works like a charm!

    Thanks Tom, much appreciated!

    #1282300
    Tim

    hi tom one question, sorry. it does not work for mobile correct? we use mobile header

    #1282719
    David
    Staff
    Customer Support

    Hi there,

    you would need to create another function like Tom provided but using this filter:

    https://docs.generatepress.com/article/generate_mobile_header_logo/

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.