最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Blog template with different header to rest of site

programmeradmin0浏览0评论

I would like to change one thing on my wordpress custom template - there are big image sliders used throughout the site except on the contact us, checkout and my account pages. The blog page was added after these were created, so in the header.php file this is what is currently there to exclude the slider images (or include) from the necessary pages:

if(!is_cart() && !is_checkout() && !is_account_page()) :
            if(is_page( 'contact-us' )):
                get_template_part( 'template-parts/header/header', 'map' ); 
            else:
                get_template_part( 'template-parts/header/header', 'slider' ); 
            endif;
        endif;

I added this to the code and it doesn't work:

if(**!is_blog() &&** !is_cart() && !is_checkout() && !is_account_page()) :
            if(is_page( 'contact-us' )):
                get_template_part( 'template-parts/header/header', 'map' ); 
            else:
                get_template_part( 'template-parts/header/header', 'slider' ); 
            endif;
        endif;  

It seemed to me that is all I would need to do but clearly I need some assistance.

I would like to change one thing on my wordpress custom template - there are big image sliders used throughout the site except on the contact us, checkout and my account pages. The blog page was added after these were created, so in the header.php file this is what is currently there to exclude the slider images (or include) from the necessary pages:

if(!is_cart() && !is_checkout() && !is_account_page()) :
            if(is_page( 'contact-us' )):
                get_template_part( 'template-parts/header/header', 'map' ); 
            else:
                get_template_part( 'template-parts/header/header', 'slider' ); 
            endif;
        endif;

I added this to the code and it doesn't work:

if(**!is_blog() &&** !is_cart() && !is_checkout() && !is_account_page()) :
            if(is_page( 'contact-us' )):
                get_template_part( 'template-parts/header/header', 'map' ); 
            else:
                get_template_part( 'template-parts/header/header', 'slider' ); 
            endif;
        endif;  

It seemed to me that is all I would need to do but clearly I need some assistance.

Share Improve this question edited Oct 9, 2019 at 12:18 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Oct 9, 2019 at 9:53 MarvynHMarvynH 34 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Try this:

if ( !is_home() && !is_cart() && !is_checkout() && !is_account_page() ) :
    if ( is_page( 'contact-us' ) ):
        get_template_part( 'template-parts/header/header', 'map' ); 
    else:
        get_template_part( 'template-parts/header/header', 'slider' );
    endif;
endif;

is_home() will return true if the current page/query is for the blog homepage, otherwise it returns false.

You can read up about is_home() on the WordPress Developer page.

You can create a separate header.php file and call it something like header-light.php. in your get_header() call you pass the one you want. Like this:

get_header( 'light' );
发布评论

评论列表(0)

  1. 暂无评论