2017-08-07 44 views
-4

我想將這些代碼添加到if語句中。可以做到嗎?將語法添加到if語句中PHP

<script> 
$(function() { 
    "use strict"; 
    $('#first_container').vegas({ 
     color: '<?php echo $wa[custom_79];?>', 
     delay: <?php echo $wa[custom_80];?>, 
     transitionDuration: <?php echo $wa[custom_133];?>, 
     timer: false, 
     transition: null, 
     slides: [ 
      <?php if ($wa[custom_82] != "" && $wa[custom_83] == "1") { $wa[custom_82] = str_replace(' ', '%20', $wa[custom_82]);?> 
       {src: '<?php echo $wa[custom_82];?>'}, 
      <?php } 
      if ($wa[custom_84] != "" && $wa[custom_85] == "1") { $wa[custom_84] = str_replace(' ', '%20', $wa[custom_84]);?> 
       {src: '<?php echo $wa[custom_84];?>'}, 
      <?php } 
      if ($wa[custom_86] != "" && $wa[custom_87] == "1") { $wa[custom_87] = str_replace(' ', '%20', $wa[custom_87]);?> 
       {src: '<?php echo $wa[custom_86];?>'}, 
      <?php } 
      if ($wa[custom_88] != "" && $wa[custom_89] == "1") { $wa[custom_89] = str_replace(' ', '%20', $wa[custom_89]);?> 
       {src: '<?php echo $wa[custom_88];?>'}, 
      <?php } 
      if ($wa[custom_90] != "" && $wa[custom_91] == "1") { $wa[custom_91] = str_replace(' ', '%20', $wa[custom_91]);?> 
       {src: '<?php echo $wa[custom_90]?>'}, 
      <?php } 
      if ($wa[custom_92] != "" && $wa[custom_93] == "1") { $wa[custom_93] = str_replace(' ', '%20', $wa[custom_93]);?> 
       {src: '<?php echo $wa[custom_92]?>'}, 
      <?php } 
      if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
       {src: '<?php echo $wa[custom_94];?>'}, 
      <?php } 
      ?> 
      <? if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
       {src:'images/1-Hov-Lean-1800px-X600px.jpg'}, 
      <? } ?> 
      <? if ($wa[custom_96] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
       {src:'images/1-Angkor-1800px-X-600px.jpg'}, 
      <? } ?> 
      <? if ($wa[custom_98] != "" && $wa[custom_95] == "1") { $wa[custom_97] = str_replace(' ', '%20', $wa[custom_97]);?> 
       {src:'images/Home-Pages-Angkor-PC.png'}, 
      <? } ?> 
      {src:'images/Home-Pages-Peakbond.png'} 
     ], 
</script> 

<?php if ($wa[custom_132] == "1") { ?> 
    <a href="#" class="previous hidden-xs" style="visibility: visible;"></a> 
    <a href="#" class="next hidden-xs" style="visibility: visible;"></a> 
<?php } ?> 

它應該是這樣的

<?php 
if($_COOKIE["size"]>800) 
    echo "I want to put those code inside here"; 
else 
    echo "Not decide yet"; 
?> 

可以這樣做,因爲我想在顯示基於設備的顯示器分辨率的幻燈片不同的圖像旗幟。謝謝

+0

你在哪裏設置cookie?你在哪裏使用橫幅? – chris85

+0

我在JavaScript中設置了cookie。 – Iqmal

回答

-1

這是你在追求什麼?如果不是,請澄清您的要求並更正您問題中的語法錯誤。

<?php if($_COOKIE["size"]>800) { 
    echo '<script>var iqmal = true;</script>'; 
    if ($wa[custom_132] == "1") { 
     echo ' 
      <a href="#" class="previous hidden-xs" style="visibility: visible;"></a> 
      <a href="#" class="next hidden-xs" style="visibility: visible;"></a> 
     '; 
    } 
?> 

<script> 
$(function() { 
    "use strict"; 
    if(iqmal) { 
     $('#first_container').vegas({ 
      color: '<?php echo $wa[custom_79];?>', 
      delay: <?php echo $wa[custom_80];?>, 
      transitionDuration: <?php echo $wa[custom_133];?>, 
      timer: false, 
      transition: null, 
      slides: [ 
       <?php if ($wa[custom_82] != "" && $wa[custom_83] == "1") { $wa[custom_82] = str_replace(' ', '%20', $wa[custom_82]);?> 
        {src: '<?php echo $wa[custom_82];?>'}, 
       <?php } 
       if ($wa[custom_84] != "" && $wa[custom_85] == "1") { $wa[custom_84] = str_replace(' ', '%20', $wa[custom_84]);?> 
        {src: '<?php echo $wa[custom_84];?>'}, 
       <?php } 
       if ($wa[custom_86] != "" && $wa[custom_87] == "1") { $wa[custom_87] = str_replace(' ', '%20', $wa[custom_87]);?> 
        {src: '<?php echo $wa[custom_86];?>'}, 
       <?php } 
       if ($wa[custom_88] != "" && $wa[custom_89] == "1") { $wa[custom_89] = str_replace(' ', '%20', $wa[custom_89]);?> 
        {src: '<?php echo $wa[custom_88];?>'}, 
       <?php } 
       if ($wa[custom_90] != "" && $wa[custom_91] == "1") { $wa[custom_91] = str_replace(' ', '%20', $wa[custom_91]);?> 
        {src: '<?php echo $wa[custom_90]?>'}, 
       <?php } 
       if ($wa[custom_92] != "" && $wa[custom_93] == "1") { $wa[custom_93] = str_replace(' ', '%20', $wa[custom_93]);?> 
        {src: '<?php echo $wa[custom_92]?>'}, 
       <?php } 
       if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
        {src: '<?php echo $wa[custom_94];?>'}, 
       <?php } 
       ?> 
       <? if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
        {src:'images/1-Hov-Lean-1800px-X600px.jpg'}, 
       <? } ?> 
       <? if ($wa[custom_96] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
        {src:'images/1-Angkor-1800px-X-600px.jpg'}, 
       <? } ?> 
       <? if ($wa[custom_98] != "" && $wa[custom_95] == "1") { $wa[custom_97] = str_replace(' ', '%20', $wa[custom_97]);?> 
        {src:'images/Home-Pages-Angkor-PC.png'}, 
       <? } ?> 
       {src:'images/Home-Pages-Peakbond.png'} 
      ] 
     }); 
    } 
}); 
</script> 

此處瞭解詳情:http://php.net/manual/en/control-structures.if.php(ESP見註釋#1)

+0

恐怕它不適合我。你可以請我給我看看。我嘗試過,但它不起作用。 – Iqmal

+0

請參閱上面的修改。 – Aydin4ik

+0

嗨艾登,我已經算出了syntaxt。感謝您的時間和答覆。真的很高興。乾杯。 – Iqmal