Verwendung von if else-Bedingungsanweisungen in WordPress-Funktionen
P粉176980522
P粉176980522 2024-03-30 10:52:50
0
2
270

Ich habe den folgenden Code:

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');

Basierend auf der Liste der Seiten im Array muss ich verschiedene Formulare bereitstellen. Ich habe derzeit Formulare wie FORM_ONE. Dieser Code beschädigt derzeit meine Website.

Wenn ich elseif & else entferne, funktioniert es, aber ich muss noch viel hinzufügen.

Kann mir jemand sagen, was ich falsch mache?

TIA

P粉176980522
P粉176980522

Antworte allen(2)
P粉663883862

删除底行的endif;

如果您想使用endif;,您必须使用以下语法:



    { html goes here }



    { html goes here }



    { html goes here }

P粉373596828

问题是在这种情况下:

else (is_page( array( 205, 399, 401, 403, 405, 407 ) ) ) {  ?>

将 else 更改为 elseif 或删除 else 之后的条件

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!