Php 目标商业商店页面菜单
我试图隐藏/交换Woocommerce中的徽标和菜单项颜色,但没有效果。基本上我的网站大部分使用标准导航,但我想一个不同的标志和不同的导航颜色出现在所有的商店相关的网页。因此,根据页面的不同,先隐藏一个,然后显示另一个 因为我的导航是透明的,所以我只想在商店页面上看到。我知道我可以通过条件标签(例如Php 目标商业商店页面菜单,php,css,wordpress,woocommerce,conditional,Php,Css,Wordpress,Woocommerce,Conditional,我试图隐藏/交换Woocommerce中的徽标和菜单项颜色,但没有效果。基本上我的网站大部分使用标准导航,但我想一个不同的标志和不同的导航颜色出现在所有的商店相关的网页。因此,根据页面的不同,先隐藏一个,然后显示另一个 因为我的导航是透明的,所以我只想在商店页面上看到。我知道我可以通过条件标签(例如 is_product_category() 但不知道如何写它来针对这些页面和交换/隐藏上面的内容。我使用的是Divi主题。如果必要的话,我可以提供图片进行澄清 感谢Wordpress负责人的帮助!
is_product_category()
但不知道如何写它来针对这些页面和交换/隐藏上面的内容。我使用的是Divi主题。如果必要的话,我可以提供图片进行澄清
感谢Wordpress负责人的帮助!!谢谢
编辑>
<?php
// This is targeting the front page as set in Dashboard => Settings => Reading and uses the logo as setup in Divi Options.
if ( is_front_page( )) {
?>
<?php
$logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && '' != $user_logo
? $user_logo
: $template_directory_uri . '/wp-content/uploads/2016/12/logo_WHITE_sm.png';
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
</a>
</div>
<?php
//This is targeting the page with the slug page-name-slug.
} elseif ( is_page( 'botanical-collection' ) ) {
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img class="custom-logo" src="/wp-content/uploads/2016/12/logo_ORIGINAL_sm.png" /><!-- Replace image path with the url to you image -->
</a>
</div>
<?php
//This is targeting the page with the id 724.
} elseif ( is_page( '724' ) ) { //can use page id or slug
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img class="custom-logo" src="https://www.example.com/wp-content/uploads/2016/12/logo_ORIGINAL_sm.png" /><!-- Replace image path with the url to you image -->
</a>
</div>
<?php
//This is what we show if previous conditions are not met. In this case, it defaults back to the logo as set in Divi options.
} else {
?>
<?php
$logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && '' != $user_logo
? $user_logo
: $template_directory_uri . '/wp-content/uploads/2016/12/logo_WHITE_sm.png';
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
</a>
</div>
<?php
}
?>
我知道两种方法:
1)条件标记:
使用wordpress和woocommerce条件标记,您将在钩住的函数(在活动主题的function.php
文件中)或直接在wordpress或woocommerce模板中使用
示例:是商店()
,是产品类别()
,是产品标签(
),是产品()
,是购物车()
,是结帐()
例如,您可以有条件地向模板中的html标记添加类或ID。
用法示例:
<?php
// Shop page
if (is_shop())
$class = ' the-shop';
// single products
if (is_product())
$class = ' single-product';
// Cart page
if (is_cart())
$class = ' the-cart';
?>
<div class="some-class<?php $class; ?>">
<a href="/some-link">Click me</a>
</div>
您可以在子主题的style.css
文件中使用它来显示/隐藏DOM元素
建议:最好使用儿童主题
根据您的更新进行更新
我已在您的代码中插入了is_shop()
条件标记
参考资料:
非常感谢您的帮助,Loic。我使用了一个儿童主题,所以我在那里很好。我的问题是我对php不熟悉,但我设法处理了这段代码(尽管它不起作用!)嘿,Loic,CSS不是问题,只是正确地定位这个页面对我来说是非常具有挑战性的。无论如何谢谢你的帮助Loic。。。我已经修改了代码,如果我把它放在tn funtions.php中,它会破坏我的网站。但是,当我在my header.php中使用上面示例1中的初始代码时,它会出现在所有页面上,但不确定如何定位divi徽标、隐藏该徽标以及在每个页面上显示新徽标!我需要它!我很感激。。我很快就会加上你。:)
<div class="some-class the-shop">
<a href="/some-link">Click me</a>
</div>
<body class="archive post-type-archive post-type-archive-product woocommerce woocommerce-page">
<?php
// This is targeting the front page as set in Dashboard => Settings => Reading and uses the logo as setup in Divi Options.
if ( is_front_page( )) {
?>
<?php
$logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && '' != $user_logo
? $user_logo
: $template_directory_uri . '/wp-content/uploads/2016/12/logo_WHITE_sm.png';
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
</a>
</div>
<?php
// ### HERE ==> THE WOOCOMMERCE SHOP PAGE (YOU CAN EDIT THE CODE BELOW)
} elseif ( is_shop() ) {
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img class="custom-logo" src="/wp-content/uploads/2016/12/logo_ORIGINAL_sm.png" /><!-- Replace image path with the url to you image -->
</a>
</div>
<?php
//This is targeting the page with the slug page-name-slug.
} elseif ( is_page( 'botanical-collection' ) ) {
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img class="custom-logo" src="/wp-content/uploads/2016/12/logo_ORIGINAL_sm.png" /><!-- Replace image path with the url to you image -->
</a>
</div>
<?php
//This is targeting the page with the id 724.
} elseif ( is_page( '724' ) ) { //can use page id or slug
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img class="custom-logo" src="https://www.example.com/wp-content/uploads/2016/12/logo_ORIGINAL_sm.png" /><!-- Replace image path with the url to you image -->
</a>
</div>
<?php
//This is what we show if previous conditions are not met. In this case, it defaults back to the logo as set in Divi options.
} else {
?>
<?php
$logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && '' != $user_logo
? $user_logo
: $template_directory_uri . '/wp-content/uploads/2016/12/logo_WHITE_sm.png';
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
</a>
</div>
<?php
}
?>