【问题标题】:PHP Structuring an if statement inside an if else statementPHP 在 if else 语句中构建 if 语句
【发布时间】:2014-02-07 09:55:38
【问题描述】:

我在 if/else 语句的“else”中创建了一个 if 语句。它可以工作。但是函数下面的代码没有运行。当我删除函数时,函数下面的代码运行。你能帮忙吗我出去。

此代码导致问题:

<?php $googleplay= get_option('director_googleplay');?>
<?php if($googleplay): ?>
    <a href="<?php print $googleplay; ?>">
       <img src="<?=IMAGES?>/googleplay.png" class=" img-responsive  top-buffer-5"  alt="Image"/>
    </>
<?php endif;;?> 

php:

<?php  $category_id = get_cat_ID('Category Name'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php if ( in_category("1") ) { ?>
       <div class="section"></div>

    <?php } elseif ( in_category("2") ) { ?>
       <div class="section"></div>

  <?php } else { ?>
      <div class="section">
          <?php $googleplay= get_option('director_googleplay');?>
          <?php if($googleplay): ?>
              <a href="<?php print $googleplay; ?>"><img src="<?=IMAGES?>/googleplay.png" class=" img-responsive  top-buffer-5"  alt="Image"/></>
          <?php endif;;?> 
       </div>
    <?php } ?>
<?php endwhile;else: ?>
    <p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>

<div class="section">
    <?php $facebook= get_option('director_facebook');
    <?php if($facebook): ?>
    <a href="<?php print $facebook; ?>"><img src="<?=IMAGES?>/Facebook.png" class=" img-responsive pull-left"alt="Image"/></>
    <?php endif; ?>
</div>

【问题讨论】:

  • 很遗憾,人们仍然使用那种嵌入的 php 风格编写代码?
  • 首先,您收到的错误信息是什么?其次,短版和长版不一样。第三,“php”中有一个身份不明的endwhile。除了其他错误。
  • @arkascha:这种风格没有错。这里的问题是代码很乱,因为嵌入的逻辑太多,粒度也不太对。
  • arkascha:Wordpress 强迫你。这是模板的唯一方法。
  • @Jon:我从来没有说过风格有问题。只是这样的代码是一团糟,因为有太多的嵌入式逻辑。 ;-)

标签: php wordpress loops if-statement


【解决方案1】:

好吧,你忘了关闭&lt;a&gt;-标签:&lt;/a&gt;,而不是&lt;/&gt;。但是,代码应该仍然“运行”,只是显示垃圾。

另外,php sn-ps 也可以通过&lt;?-Tag 来启动和结束,你的代码中有一个:

<img src="/googleplay.png" class=" img-responsive top-buffer-5" alt="Image"/>

应该可以。删除可能导致问题的&lt;?=IMAGES?&gt;。你想用&lt;?=IMAGES?&gt;做什么?

【讨论】:

  • 你好 nekaab。我正在使用 =IMAGES?> 从 =IMAGES?> 正在执行的函数中检索代码以获取图像的位置。
  • 好的,我通过添加一个额外的 else 语句让它工作了。虽然它没有意义。一定是一些wordpress错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-04-09
  • 1970-01-01
  • 2021-04-11
  • 2015-07-07
  • 2017-02-05
  • 1970-01-01
  • 2015-07-06
相关资源
最近更新 更多