【问题标题】:Fatal error: 'continue' not in the 'loop' or 'switch' context致命错误:“继续”不在“循环”或“切换”上下文中
【发布时间】:2020-10-14 21:51:54
【问题描述】:

我相当确定这个错误是由 PHP 更新引起的,类似于这篇文章 (Fatal error: 'break' not in the 'loop' or 'switch' context in),我只是不知道如何更正代码。

我收到此错误:

致命错误:“继续”不在第 32 行 [模板名称] 中的“循环”或“切换”上下文中

这是第 32 行的代码:

<h2><a href="<?php if(is_wp_error( $term_link )) {continue;} else {echo esc_url( $term_link );}  ?>"><?php echo $term_name; ?></a></h2>

我该如何解决?

【问题讨论】:

  • 为什么你需要一个不属于循环的continue?这在哪种情况下有意义?
  • 删除continue;
  • continue 和 break 语句是循环的一部分。在这里,您没有使用任何循环。请确保您使用的是循环(for、while)。
  • 我删除了整行代码。现在一切似乎都运行良好。感谢您的建议!

标签: php wordpress


【解决方案1】:

你把这弄得太复杂了。只需反转条件:

<h2><a href="<?php if (!is_wp_error( $term_link )) { echo esc_url( $term_link ); }  ?>"><?php echo $term_name; ?></a></h2>

【讨论】:

    猜你喜欢
    • 2016-06-25
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    相关资源
    最近更新 更多