downloadTemp2014 2015-07-24 08:52
浏览 46
已采纳

如果语句不起作用,则输出else语句

I'm trying to output the if statement, but instead the else statement shows. I have created a page using Wordpress and assigned this template to the page. I'm trying to show product image and content if number of products is > 0, which it is. But instead it shows the else statement. Can someone please help?

<?php  
/*
Template Name: Product Single Template
*/
$productsPermalink = pods_var('last', 'url');
$singleProductPod = pods('products', $productsPermalink);
$numProducts = $singleProductPod->total();
?>

<?php get_header(); ?>

<section>
<?php  if($numProducts > 0): 
?>

    <h1><?php echo $singleProductPod->field('name'); ?></h1>

    <div class="instructor single">
        <img src="<?php echo $singleProductPod->field('image.guid') ?>" alt="<?php echo $singleProductPod->field('name')?>">
        <p><?php echo $singleProductPod->field('content')?></p>
    </div>


<?php  else: ?>
    <h3>There is no such product: <?php echo $productsPermalink; ?>, please select another product</h3>
<?php endif; ?>

  • 写回答

1条回答 默认 最新

  • dougang6178 2015-07-24 09:03
    关注

    It probably shows the if statement because in the line <?php if($numProducts > 0): you have the condition that if the value $numProducts is less than 0 it should instead execute the else clause.

    Try and use die (var_dump ($numProducts)); to see the output and find out what really is going on. While you're at it try using var_dump on $singleProductPod->total(); as well.

    Maybe you'll find out that the values of these variables isn't quite what you thought it would be.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据