У меня есть следующий код:
function wpb_hook_javascript() {
if (is_page( array( 244, 174, 697, 702, 699, 708, 713 ) ) ) {
?>
<noscript>
<iframe src = "FORM_ONE" width = "100%" height = "550" type = "text/html" frameborder = "0" allowTransparency = "true" style = "border: 0"></iframe>
</noscript>
<script type = "text/javascript">
var form = 'FORM_ONE';
var params = window.location.search;
var thisScript = document.scripts[document.scripts.length - 1];
var iframe = document.createElement('iframe');
iframe.setAttribute('src', form + params);
iframe.setAttribute('width', '100%');
iframe.setAttribute('height', 550);
iframe.setAttribute('type', 'text/html');
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowTransparency', 'true');
iframe.style.border = '0';
thisScript.parentElement.replaceChild(iframe, thisScript);
</script>
<?php }
elseif (is_page( array( 187, 283, 285, 287, 18608, 18619, 18629, 295, 297, 299, 303, 305, 307 ) ) ) { ?>
<noscript>
<iframe src = "FORM_TWO" width = "100%" height = "550" type = "text/html" frameborder = "0" allowTransparency = "true" style = "border: 0"></iframe>
</noscript>
<script type = "text/javascript">
var form = 'FORM_TWO';
var params = window.location.search;
var thisScript = document.scripts[document.scripts.length - 1];
var iframe = document.createElement('iframe');
iframe.setAttribute('src', form + params);
iframe.setAttribute('width', '100%');
iframe.setAttribute('height', 550);
iframe.setAttribute('type', 'text/html');
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowTransparency', 'true');
iframe.style.border = '0';
thisScript.parentElement.replaceChild(iframe, thisScript);
</script>
<?php }
else (is_page( array( 205, 399, 401, 403, 405, 407 ) ) ) { ?>
<noscript>
<iframe src = "FORM_THREE" width = "100%" height = "550" type = "text/html" frameborder = "0" allowTransparency = "true" style = "border: 0"></iframe>
</noscript>
<script type = "text/javascript">
var form = 'FORM_THREE';
var params = window.location.search;
var thisScript = document.scripts[document.scripts.length - 1];
var iframe = document.createElement('iframe');
iframe.setAttribute('src', form + params);
iframe.setAttribute('width', '100%');
iframe.setAttribute('height', 550);
iframe.setAttribute('type', 'text/html');
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowTransparency', 'true');
iframe.style.border = '0';
thisScript.parentElement.replaceChild(iframe, thisScript);
</script>
<?php }
}
add_action('wp_head', 'wpb_hook_javascript');
В зависимости от списка страниц в массиве мне нужно обслуживать другую форму. В настоящее время у меня есть формы, где у меня есть FORM_ONE и т. д. Этот код в настоящее время ломает мой сайт.
Если я удалю elseif & else, это сработает, НО мне есть что добавить.
Может ли кто-нибудь сказать мне, что я сделал неправильно?
ТИА
Удалите endif;
в нижней строке.
Если вы хотите использовать endif;
, вы должны использовать следующий синтаксис:
<?php if ( condition ) : ?>
{ html goes here }
<?php elseif ( condition ): ?>
{ html goes here }
<?php else : ?>
{ html goes here }
<?php endif; ?>
Вы уверены, что ошибка именно в этом фрагменте? Какое сообщение об ошибке вы получаете?
Проблема в таком состоянии:
else (is_page( array( 205, 399, 401, 403, 405, 407 ) ) ) { ?>
Либо измените else на elseif
, либо удалите условие после else
Кажется, работает, спасибо. Я думал, что последний в длинном выражении if else должен быть else.
Без проблем. Для этого нет ограничений, вы можете иметь столько elseif
, сколько хотите, не указывая else
.
Я удалил его и все еще ломает сайт: