Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 条件语句_Php_Wordpress - Fatal编程技术网

Php 条件语句

Php 条件语句,php,wordpress,Php,Wordpress,我试图根据用户所在的页面显示横幅图像: <?php if ( is_product_category('cocktail-catering-packages') ) { ?> <div id="page_caption" class="hasbg parallax " data-image="<?php echo get_bloginfo('template_directory');?>/images/banner08.jpg" data-width="21

我试图根据用户所在的页面显示横幅图像:

<?php if ( is_product_category('cocktail-catering-packages') ) { ?>
    <div id="page_caption" class="hasbg parallax " data-image="<?php echo get_bloginfo('template_directory');?>/images/banner08.jpg" data-width="2142" data-height="454">
<?php } ?>
<?php if ( is_product_category('sweet-bites') ) { ?>
    <div id="page_caption" class="hasbg parallax " data-image="<?php echo get_bloginfo('template_directory');?>/images/banner10.jpg" data-width="2142" data-height="454">
<?php } ?>
<?php else { ?>
    <div id="page_caption" class="hasbg parallax " data-image="<?php echo get_bloginfo('template_directory');?>/images/banner04.jpg" data-width="2142" data-height="454">
<?php } ?>

由于我不熟悉PHP,请有人帮助我如何创建此条件语句。

这应该适用于您:

(只需在
else
之前获取
}



只需编写更清晰的代码即可帮助您诊断问题:

function showBanner($filename)
{
  $url = get_bloginfo('template_directory').'/images/'.$filename;
  echo '<div id="page_caption" class="hasbg parallax" data-image="'.$url.
       '" data-width="2142" data-height="454">';
}  

if (is_product_category('cocktail-catering-packages')) 
{
  showBanner('banner08.jpg');
}  
else if (is_product_category('sweet-bites'))
{
  showBanner('banner10.jpg');
}
else 
{ 
  showBanner('banner04.jpg');
}
函数showBanner($filename)
{
$url=get_bloginfo('template_directory')。/images/'.$filename;
回声';
}  
如果(是产品类别(“鸡尾酒-餐饮-套餐”)
{
showBanner(“banner08.jpg”);
}  
否则,如果(是产品类别(“甜食”))
{
showBanner('banner10.jpg');
}
其他的
{ 
showBanner(“banner04.jpg”);
}

哪一行是513?这是包含代码> >代码>的代码吗?代码中提供的最后三行可能需要考虑在PHP中使用,特别是在构建HTML时。它更容易阅读和调试。错!OP的代码中没有
else if
!啊,你很快就发现了!:-)我想这可能是问题代码中的一个提示。如果你想知道的话,我在30秒内读你的代码时发现了它!为什么这个答案会得到支持和接受,即使它甚至没有做OP的代码所做的事情?!好问题,因为您找到了错误消息的真正原因。我想我的建议很受欢迎。
<?php if ( is_product_category('cocktail-catering-packages') ) { ?>
    <div id="page_caption" class="hasbg parallax " data-image="<?php echo get_bloginfo('template_directory');?>/images/banner08.jpg" data-width="2142" data-height="454">

<?php } ?>
<?php if ( is_product_category('sweet-bites') ) { ?>
    <div id="page_caption" class="hasbg parallax " data-image="<?php echo get_bloginfo('template_directory');?>/images/banner10.jpg" data-width="2142" data-height="454">

<?php } else { ?>
    //^Here i have the '}' before the else statement and NOT in separate php tags
    <div id="page_caption" class="hasbg parallax " data-image="<?php echo get_bloginfo('template_directory');?>/images/banner04.jpg" data-width="2142" data-height="454">

<?php } ?>
function showBanner($filename)
{
  $url = get_bloginfo('template_directory').'/images/'.$filename;
  echo '<div id="page_caption" class="hasbg parallax" data-image="'.$url.
       '" data-width="2142" data-height="454">';
}  

if (is_product_category('cocktail-catering-packages')) 
{
  showBanner('banner08.jpg');
}  
else if (is_product_category('sweet-bites'))
{
  showBanner('banner10.jpg');
}
else 
{ 
  showBanner('banner04.jpg');
}