Tagged: 

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #663423

    Hello,

    we found this code in an old post an insert it in the theme functions.php

    add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); 
    function add_banner_before_breadcrumb() {
    	if ( is_product() )
    	{
    		echo '<h1 style="text-align: center;"><a href="http://www.yourwebsite.com" target="_blank">
    <img border="0" alt="Banner Name" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image.jpg" style="float: left; z-index: 99999; width: 100%;"></h1>';
    	}
    }

    this works fine for all product details page. but we want different headers on all category + the category header image for the specific detail pages.

    Sample:
    Header-1:
    only Product Main Page

    Header-2:
    Category-1 main page
    + all product_detail pages from category-1 use header-2

    Header-3:
    Category-2 main page
    + all product_detail pages from category-2 use header-3

    Header-4:
    Category-3 main page
    + all product_detail pages from category-3 use header-4

    and so on….

    many thanks for help! :-)

    #663471

    the point is if ( is_product() )

    see reference here: https://docs.woocommerce.com/wc-apidocs/function-is_product.html

    so you have to combine this rule f.e.:

    function add_banner_before_breadcrumb() {
    	if ( is_product() || is_product_category() )
    	{

    etc.

    if you want different on products and on categories than i think you have to use for each.
    i’m not so familiar with that – so wait till a mod looks to your question if an if elseif case could work.

    add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); 
    function add_banner_before_breadcrumb() {
    	if ( is_product() )
    	{
    		    echo '<h1 style="text-align: center;"><a href="http://www.yourwebsite.com" target="_blank">
    			<img border="0" alt="Banner Name" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image.jpg" style="float: left; z-index: 99999; width: 100%;"></h1>';
    	};
    
    	elseif ( is_product_category() )
    	{
    		echo '<h1 style="text-align: center;"><a href="http://www.yourwebsite.com" target="_blank">
    			<img border="0" alt="Banner Name 2" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image2.jpg" style="float: left; z-index: 99999; width: 100%;"></h1>';
    	}
    }
    • This reply was modified 8 years, 4 months ago by Guenni007.
    #663481

    btw. you can see these logical operators here:

    http://php.net/manual/en/language.operators.logical.php

    #663833

    Hi @envato1901,

    Did you try @Guenni007’s suggestions and did you have any luck with them?

    Thanks,
    Rikard

    #663895

    Hello,

    yes, i try it – thanks to guenni007 :-)
    the code now looks like:

    add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); 
    function add_banner_before_breadcrumb() {
    	if ( is_product_category() AND has_term('6', 'product_cat'))
    	{
    		echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-1.jpg" style="float: left; z-index: 99999; width: 100%;">';
    	}
    
    	elseif ( is_product_category() AND has_term('17', 'product_cat'))
    	{
    		echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-2.jpg" style="float: left; z-index: 99999; width: 100%;">';
    	}
    
    	elseif ( is_product() )
    	{
    		echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-3.jpg" style="float: left; z-index: 99999; width: 100%;">';
    	}
    }

    with the term id i can set the categories for the banner. but i dont know how i combinate category 6 + all only all products from cat. 6 have to use banner 1. And all products from category 17 have to use banner 2 from category 17. the last elseif ( is_product() ) must in elseif ( is_product_category() AND has_term(’17’, ‘product_cat’)).

    #665138

    if you like to select the category 17 and all products from category 17.

    I don’t like to install a demo shop to help you – so you have to have a look for yourself.
    if a single product is shown – doesn’t it have the product category too in his source code.
    so when you selectis_product_category('17') this does automatically even select all single products of that category?

    #665239

    Hi,

    thanks guys for sharing your wisdom with us :).

    Best regards,
    Andy

    #665287

    Hello,

    no guenni007 it not works with is_product_category(’17’) for the single produtcs in the category. But now i think i have a solution for this. i will see if this works for more than three categories

    add_action('ava_after_main_container', 'add_banner_before_breadcrumb'); 
    function add_banner_before_breadcrumb() {
    	if ( is_product_category || is_product AND has_term('17', 'product_cat'))
    	{
    		echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-1.jpg" style="float: left; z-index: 99999; width: 100%;">';
    	}
    
    	elseif ( is_product_category || is_product AND has_term('6', 'product_cat'))
    	{
    		echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-2.jpg" style="float: left; z-index: 99999; width: 100%;">';
    	}
    
    	elseif ( is_product_category || is_product AND has_term('16', 'product_cat'))
    	{
    		echo '<img border="0" alt="" src="http://www.yourwebsite.com/wp-content/uploads/shop-banner-image-3.jpg" style="float: left; z-index: 99999; width: 100%;">';
    	}
    }

    hope the code is conform with the rest of the code. :-)

    #665668

    have some questions to the style experts.

    how can I max . height for the banner determine. If I draw the window smaller the graphic is also small, it looks responsive. But the picture will be very squashed you can do this better? thanks for help!

    #676967

    Hello,

    where can I find the Term ID for the Main Page Shop where all categories are displayed? It use a wrong Banner from my code so i want to tell that it is empty.

    elseif ( is_product AND has_term('HERE I NEED THE ID', 'product_cat'))
    	{
    		echo '<img border="0" alt="" src="http://xyz.com/wp-32e86-content/uploads/2016/08/mainpage_empty_banner.png" style="float: left; z-index: 99999; width: 100%;">';
    	}
    #676975

    Hey!

    That must be the main page to be honest ( shop from Pages ) and not the term ID. So I think it is better for that page, to replace it with is_page.
    Let us know if that works

    Best regards,
    Basilis

    #676987

    Hello,

    thanks for help!

    when i only use

    
    	elseif ( is_page )
    	{
    		echo 'Test Test Test';
    	}

    the rest of the category code works but the Main Page do nothing. Have i to use for is_page the post ID from the Shopsite?

    the products site have the post.php?=post=202 id.

    #678873

    Hi,

    yes, and or more information about this standard WordPress functions refer to: https://developer.wordpress.org/reference/functions/is_page/

    Best regards,
    Andy

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