Support

Account

Home Forums Add-ons Repeater Field Repeater field elseif help

Solving

Repeater field elseif help

  • Hi wondered if someone could help me i have:

    this code:

    and i need to have an else or elseif statement so reads like:

    <?php if( have_rows('downloads') ): ?>
    	<ul class="slides">
    
    	<?php while( have_rows('downloads') ): the_row();
    
    		// vars
    		$windows = get_sub_field('windows');
    		$macosx = get_sub_field('macosx');
    		$linux = get_sub_field('linux');
    		
    
    		?>
    
    		<li class="slide">
    
    			<?php if( $windows ): ?>
    				<a href="<?php echo $windows; ?>"><?php echo $os; ?></a>
    			<?php elseif( $macosx ): ?>
    				<a href="<?php echo $macosx; ?>"><?php echo $os; ?></a>
    			<?php elseif( $linux ): ?>
    				<a href="<?php echo $linux; ?>"><?php echo $os; ?></a>
    			<?php endif; ?>
    			
    			
    			
    
    		    <?php echo $content; ?>
    
    		</li>
    
    	<?php endwhile; ?>
    
    	</ul>
    <?php endif; ?>

    but this does not seem to work as it still outputs the windows .exe file does not recognise the elseif πŸ™

  • What type of fields hare these and what do you have them set to return if that option is available?

  • Hi John,

    Basiclally i have a php script which is this:

    <?php
     
    // Simple browser and OS detection script.
    // This will not work if User Agent is false.
     
    $agent = $_SERVER['HTTP_USER_AGENT'];
     
    // Detect Device/Operating System
     
    if(preg_match('/Linux/i',$agent)) $os = 'Linux';
      elseif(preg_match('/Mac/i',$agent)) $os = 'Mac';
      elseif(preg_match('/iPhone/i',$agent)) $os = 'iPhone';
      elseif(preg_match('/iPad/i',$agent)) $os = 'iPad';
      elseif(preg_match('/Droid/i',$agent)) $os = 'Droid';
      elseif(preg_match('/Unix/i',$agent)) $os = 'Unix';
      elseif(preg_match('/Windows/i',$agent)) $os = 'Windows';
      else $os = 'Unknown';
    ?>

    so i was going to use a repeater field to and create a sub field called:

    Windows and another called: Linux and another called Macosx so if on a Windows it displays the Windows field. and if on a Linux computer it shows hte Linux Field etc.

    Thanks
    Aaron

  • 
    if ($os == 'Windows' && get_sub_field('windows')) {
      // show a value
    }
    

    although I would probably use a switch statement

    
    switch ($os) {
      case 'windows':
        $value = get_sub_field('windows');
        break;
      case 'Mac'
        $value = get_sub_field('mac');
        break;
      // etc fro each os and field
    }
    
    if ($value) {
      echo $value;
    }
    
    
  • Nice πŸ™‚ will give that a go but i did it different method.

    <?php if ( $os == Linux ) { ?> <a href="<?php echo $linux; ?>"><?php echo $os ?></a><br /><br /> <?php } ?>
    <?php if ( $os == Windows ) { ?> <a href="<?php echo $windows; ?>"><?php echo $os ?></a><br /><br /> <?php } ?>
    <?php if ( $os == Mac ) { ?>  <a href="<?php echo $macosx; ?>"><?php echo $os ?></a><br /><br /> <?php } ?>

    And it works perfectly at the moment,

    But it has gave me some insite for something else i amy need to do πŸ™‚

    Thanks
    John

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.