Php 在if语句中同时使用多个条件标记
我对Php 在if语句中同时使用多个条件标记,php,wordpress,if-statement,woocommerce,shortcode,Php,Wordpress,If Statement,Woocommerce,Shortcode,我对is\u cart(),is\u checkout(),is\u account\u page()函数有问题 我想做的是: 如果是购物车页面,则回显此短代码 如果它不是购物车页面,那么什么也不做 这需要发生在页面的顶部和底部,都在页面容器的外部 当我查看购物车、结帐、账户页面时,它工作得完美无缺。但是,只要我查看任何其他非购物车/结帐/帐户页面的页面,短代码仍然会显示 该网站正在与WooCommerce一起使用Divi主题(按ElegantThemes)。 以下是我正在处理的代码片段:
is\u cart()
,is\u checkout()
,is\u account\u page()函数有问题
我想做的是:
- 如果是购物车页面,则回显此短代码
- 如果它不是购物车页面,那么什么也不做
这需要发生在页面的顶部和底部,都在页面容器的外部
当我查看购物车、结帐、账户页面时,它工作得完美无缺。但是,只要我查看任何其他非购物车/结帐/帐户页面的页面,短代码仍然会显示
该网站正在与WooCommerce一起使用Divi主题(按ElegantThemes)。
以下是我正在处理的代码片段:
<?php if ( ! (function_exists('is_cart') && is_cart()) || ( ! function_exists('is_account_page') && is_account_page()) || ( ! function_exists('is_checkout') && is_checkout() ) ) : ?>
<?php echo do_shortcode('[et_pb_section global_module="218"][/et_pb_section]'); ?>
<?php endif; ?>
如果我理解的很好,你想输出这个短码的内容只在购物车,结帐和帐户页面
那么您最好尝试以下较短的方法:
<?php
if ( class_exists( 'WooCommerce' ) && ( is_cart() || is_account_page() || is_checkout() ) ) :
echo do_shortcode('[et_pb_section global_module="247"][/et_pb_section]');
endif;
?>
<?php
get_header();
$is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
?>
<?php if ( ! (function_exists('is_cart') && is_cart()) || ( ! function_exists('is_account_page') && is_account_page()) || ( ! function_exists('is_checkout') && is_checkout() ) ) : ?>
<?php echo do_shortcode('[et_pb_section global_module="218"][/et_pb_section]'); ?>
<?php endif; ?>
<div id="main-content">
<?php if ( ! $is_page_builder_used ) : ?>
<div class="container">
<div id="content-area" class="clearfix">
<div id="left-area">
<?php endif; ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( ! $is_page_builder_used ) : ?>
<h1 class="entry-title main_title"><?php the_title(); ?></h1>
<?php
$thumb = '';
$width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );
$height = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
$classtext = 'et_featured_image';
$titletext = get_the_title();
$thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
$thumb = $thumbnail["thumb"];
if ( 'on' === et_get_option( 'divi_page_thumbnails', 'false' ) && '' !== $thumb )
print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height );
?>
<?php endif; ?>
<div class="entry-content">
<?php
the_content();
if ( ! $is_page_builder_used )
wp_link_pages( array( 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'Divi' ), 'after' => '</div>' ) );
?>
</div> <!-- .entry-content -->
<?php
if ( ! $is_page_builder_used && comments_open() && 'on' === et_get_option( 'divi_show_pagescomments', 'false' ) ) comments_template( '', true );
?>
</article> <!-- .et_pb_post -->
<?php endwhile; ?>
<?php if ( ! $is_page_builder_used ) : ?>
</div> <!-- #left-area -->
<?php get_sidebar(); ?>
</div> <!-- #content-area -->
</div> <!-- .container -->
<?php endif; ?>
<?php if ( ! (function_exists('is_cart') && is_cart()) || ( ! function_exists('is_account_page') && is_account_page()) || ( ! function_exists('is_checkout') && is_checkout() ) ) : ?>
<?php echo do_shortcode('[et_pb_section global_module="247"][/et_pb_section]'); ?>
<?php endif; ?>
</div> <!-- #main-content -->
<?php get_footer(); ?>
<?php
if ( class_exists( 'WooCommerce' ) && ( is_cart() || is_account_page() || is_checkout() ) ) :
echo do_shortcode('[et_pb_section global_module="247"][/et_pb_section]');
endif;
?>