Php 我找到了一些与if-else相关的代码,并尝试更改语法,但没有';行不通
更新: 感谢大家的精彩输入,我现在在主页上的代码工作正常。仍然无法理解为什么相同的代码在小部件中不起作用。它正在下拉标题和永久链接,因此我知道它正在获取数据,但自定义值返回为零 我正在制作一个wordpress页面,其中使用该页面的小组正在接受观众的挑战 挑战页面是一个特殊的模板,显示挑战完成程度的百分比栏 该条工作正常,chrome中有一个小故障,但客户希望对完成率为0%的挑战“挂起”,对100%的挑战“完成”,而不是图形 我把这段代码放进了页面和一个小部件中,结果都很奇怪。在页面上,只有百分比栏显示,但在小部件上,所有挑战都列为“待定” 我的页面代码如下:Php 我找到了一些与if-else相关的代码,并尝试更改语法,但没有';行不通,php,wordpress,if-statement,Php,Wordpress,If Statement,更新: 感谢大家的精彩输入,我现在在主页上的代码工作正常。仍然无法理解为什么相同的代码在小部件中不起作用。它正在下拉标题和永久链接,因此我知道它正在获取数据,但自定义值返回为零 我正在制作一个wordpress页面,其中使用该页面的小组正在接受观众的挑战 挑战页面是一个特殊的模板,显示挑战完成程度的百分比栏 该条工作正常,chrome中有一个小故障,但客户希望对完成率为0%的挑战“挂起”,对100%的挑战“完成”,而不是图形 我把这段代码放进了页面和一个小部件中,结果都很奇怪。在页面上,只有百分
<?php
/**
* Template Name: Challenges Page
*/
?>
<?php get_header(); ?>
<!-- content -->
<div id="content">
<?php query_posts( array( 'post_type' => 'challenges', 'posts_per_page' => -1 ) ); ?>
<?php while (have_posts()) : the_post(); $more = 0; ?>
<div class="post archive">
<div class="post-comments"><?php comments_popup_link('0', '1', '%'); ?></div>
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<?php
$target = get_post_meta($post->ID, 'target', true);
$complete = get_post_meta($post->ID, 'complete', true);
$percentage = $complete / $target;
$percentage = round($percentage * 100);
$whatsleft = 100-$percentage;
if($whatsleft < 0) $whatsleft=0;
echo "<table width='250' border='0' cellpadding='0' cellspacing='0'><tr>";
if($complete == $target) {
echo "<td><img src='http://www.smokeyvstheworld.com/wp-content/uploads/2012/05/completed.gif' style='width:200>px;height:24px;'></td>";
} else if ($complete == 0) {
echo "<td><img src='http://www.smokeyvstheworld.com/wp-content/uploads/2012/05/pending.gif' style='width:200>px;height:24px;'></td>";
} else {
echo "<td><img src='http://www.smokeyvstheworld.com/wp-content/themes/spectre/images/brown/grnbar.jpg' style='width:". $percentage ."px;height:12px;'></td><td><img src='http://www.smokeyvstheworld.com/wp-content/themes/spectre/images/brown/grybar.jpg' style='width:". $whatsleft ."px;height:12px;'></td>";
}
echo "</tr><tr><td colspan='2'><div align='right'>". $complete ." of ". $target ." completed</div></td></tr></table>";
?>
<div class="post-date"><?php the_time('l, F jS, Y') ?></div>
<?php if (get_post_meta($post->ID, 'post_image_value', true)) { ?><div class="post-tnail"><a href="<?php the_permalink() ?>"><?php if (get_post_meta($post->ID, 'post_image_value', true) && $mb_resize == 0) { ?><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>&w=98&h=98&zc=1&q=95" alt="<?php the_title(); ?>" /><?php } else if (get_post_meta($post->ID, 'post_image_value', true) && $mb_resize == 1) { ?><img src="<?php bloginfo('home'); ?><?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>" alt="<?php the_title(); ?>" /><?php } ?></a></div><?php } ?>
<?php the_excerpt() ?>
<p><a href="<?php the_permalink() ?>" class="more">Continue reading...</a></p>
</div>
<?php endwhile; ?>
</div>
<div id="sidebar"><?php get_sidebar(); ?></div>
<?php get_footer(); ?>
width:200>px;高度:24px代码>=>宽度:200px;高度:24px代码>试试看
$target = (int) get_post_meta($post->ID, 'target', true);
$complete = (int) get_post_meta($post->ID, 'complete', true);
$target=(int)get_post_meta($post->ID,'target',true);
$complete=(int)get_post_meta($post->ID,'complete',true);
尝试将==
更改为==
,以便:
if($complete === $target) {
及
编辑:
仔细想想,$complete值可能是一个字符串,因此如果上面的代码不起作用,请将该行更改为
} else if ($complete === "0") {
你能先格式化你的代码吗?你已经发布了大量的代码。我已经尽力将其格式化,但请确保只包含与实际相关的部分代码。这肯定是一个错误,但即使修复了该错误,if和elseif也不会被解析到页面echo''$完成“of”$目标:“完成”代码>输出是什么?输出显示页面中自定义字段的值,但小部件中没有显示任何值。它在栏上也显示了正确的百分比(除了在chrome中),完成时得到0,表单目标得到0。您是否使用了正确的元名称(完整,目标)。你能展示一些代码,原始的绿色条在哪里工作,并得到执行后的元吗?这在小部件中。页面左侧的代码显示了条形图,相同挑战的数字是正确的,但它不会显示“待定”或“已完成”,请尝试安装$post->ID。。我甚至试着切换我使用的变量,所以如果百分比是,你确定这些元值是正确的吗?$post中是否有您期望的内容?请在$post上做一个var_转储,看看它是否是正确的帖子。事实上,它修复了大多数问题,我可以在帖子中使用它(还没有在小部件中,但谢谢!!)
} else if ($complete === "0") {