【发布时间】: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