← PHP

ajuda com IF-THEN-ELSE

Lida 2531 vezes

Offline

raugusto 
Elite
Mensagens 3145 Gostos 33
Feedback +13

Troféus totais: 31
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

alguem me pode validar esta condição? dá parsing error no wordpress:

Código: [Seleccione]
<?php if($col[2]){ ?><div class="grid_3"><?php ?>
<?php if($col[2]){ ?>
                  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('column_2_'.$post_sidebar[0]) ) : endif; ?>
<?php else { ?>
                     <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('column_3') ) : endif; ?>
         <?php ?><?php ?>
<?php if($col[2]){ ?></div><?php ?>
Offline

RonaldoFS 
Membro
Mensagens 18 Gostos 1
Troféus totais: 20
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 4 Level 3 Level 2 Level 1 10 Posts First Post

Sou newbie em php, mas isso pode ser escrito de uma maneira melhor... apesar de não perceber o que estão a fazer os if-else mais internos.

Aqui vai a mesma lógica, mas numa maneira mais legível (pelo menos paramim  :) ):

Código: [Seleccione]
<?php if($col[2]): ?>
  <div class="grid_3">
    <?php
      
if($col[2]) {
        if ( !
function_exists('dynamic_sidebar') || !dynamic_sidebar('column_2_'.$post_sidebar[0]) ): endif;
      }
      else
      {
        if ( !
function_exists('dynamic_sidebar') || !dynamic_sidebar('column_3') ) : endif;
      }
    
?>

  </div>
<?php endif ?>

Espero que ajude.
Offline

raugusto 
Elite
Mensagens 3145 Gostos 33
Feedback +13

Troféus totais: 31
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

é mais ou menos, quero que o ELSE seja deste if:

Código: [Seleccione]
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('column_2_'.$post_sidebar[0]) ): endif;
e não deste:

Código: [Seleccione]
if($col[2])
Offline

epsy 
Membro
Mensagens 553 Gostos 1
Feedback +1

Troféus totais: 25
Trófeus: (Ver todos)
Search Windows User Super Combination Combination Topic Starter Poll Voter Level 4 Level 3 Level 2 Level 1

Experimementa assim:

Código: (php) [Seleccione]
<?php
  
//inicio if 1
  
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('column_2_'.$post_sidebar[0]) ) 
  {
//whatever
  
//fim do if 1
   
else { 
   
?>

  <?php 
        
//inicio if 2
        
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('column_3') ) { ?>

  <?php
// whatever
  
?>

  <?php //fim do if 2 ?>
  <?php //fim do else ?>

Offline

raugusto 
Elite
Mensagens 3145 Gostos 33
Feedback +13

Troféus totais: 31
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

thanks vou testar