1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need Help with php code

Discussion in 'PHP' started by Wp-Mod.Com, Jan 21, 2010.

  1. #1
    ok i was designing wordpress theme when i decided to add 125x125 ads to the code now i am facing a problem that user can select how many ads they want to show , for eg 2,4,6,8 default is 2 , if user selects 4 it will show 4 ads , but when user selects 6 ads then it shows only 4 skipping the in between ads no. 3 and 4 and showing 5 and 6 same for ads 7 and 8

    here is my code

                <a href="<?php echo $wpmod_show_image_1_link; ?>"><img src="<?php echo $wpmod_show_image_1; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_1_title; ?>" title="<?php echo $wpmod_show_image_1_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_2_link; ?>"><img src="<?php echo $wpmod_show_image_2; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_2_title; ?>" title="<?php echo $wpmod_show_image_2_title; ?>" /></a>
    <?php if (get_option('wpmod_ads_number') == '4') { ?>
                <a href="<?php echo $wpmod_show_image_3_link; ?>"><img src="<?php echo $wpmod_show_image_3; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_3_title; ?>" title="<?php echo $wpmod_show_image_3_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_4_link; ?>"><img src="<?php echo $wpmod_show_image_4; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_4_title; ?>" title="<?php echo $wpmod_show_image_4_title; ?>" /></a>
    <?php } elseif (get_option('wpmod_ads_number') == '6') { ?>
                <a href="<?php echo $wpmod_show_image_5_link; ?>"><img src="<?php echo $wpmod_show_image_5; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_5_title; ?>" title="<?php echo $wpmod_show_image_5_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_6_link; ?>"><img src="<?php echo $wpmod_show_image_6; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_6_title; ?>" title="<?php echo $wpmod_show_image_6_title; ?>" /></a>
     <?php } elseif (get_option('wpmod_ads_number') == '8') { ?>
                <a href="<?php echo $wpmod_show_image_7_link; ?>"><img src="<?php echo $wpmod_show_image_7; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_7_title; ?>" title="<?php echo $wpmod_show_image_7_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_8_link; ?>"><img src="<?php echo $wpmod_show_image_8; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_8_title; ?>" title="<?php echo $wpmod_show_image_8_title; ?>" /></a>
    <?php } ?>
    PHP:
    any option seleted from 6 and 8 eventually displays 4 ads whereas i want to show 6 and 8 ads repectively
     
    Wp-Mod.Com, Jan 21, 2010 IP
  2. Djkanna

    Djkanna Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi, you could always try checking if it's greater than or equal to the number of ads

    
    <a href="<?php echo $wpmod_show_image_1_link; ?>"><img src="<?php echo $wpmod_show_image_1; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_1_title; ?>" title="<?php echo $wpmod_show_image_1_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_2_link; ?>"><img src="<?php echo $wpmod_show_image_2; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_2_title; ?>" title="<?php echo $wpmod_show_image_2_title; ?>" /></a>
    <?php if (get_option('wpmod_ads_number') >= '4') { ?>
                <a href="<?php echo $wpmod_show_image_3_link; ?>"><img src="<?php echo $wpmod_show_image_3; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_3_title; ?>" title="<?php echo $wpmod_show_image_3_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_4_link; ?>"><img src="<?php echo $wpmod_show_image_4; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_4_title; ?>" title="<?php echo $wpmod_show_image_4_title; ?>" /></a>
    <?php } elseif (get_option('wpmod_ads_number') >= '6') { ?>
                <a href="<?php echo $wpmod_show_image_5_link; ?>"><img src="<?php echo $wpmod_show_image_5; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_5_title; ?>" title="<?php echo $wpmod_show_image_5_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_6_link; ?>"><img src="<?php echo $wpmod_show_image_6; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_6_title; ?>" title="<?php echo $wpmod_show_image_6_title; ?>" /></a>
     <?php } elseif (get_option('wpmod_ads_number') >= '8') { ?>
                <a href="<?php echo $wpmod_show_image_7_link; ?>"><img src="<?php echo $wpmod_show_image_7; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_7_title; ?>" title="<?php echo $wpmod_show_image_7_title; ?>" /></a>
                <a href="<?php echo $wpmod_show_image_8_link; ?>"><img src="<?php echo $wpmod_show_image_8; ?>" width="125" height="125" alt="<?php echo $wpmod_show_image_8_title; ?>" title="<?php echo $wpmod_show_image_8_title; ?>" /></a>
    <?php } ?>
    PHP:
     
    Djkanna, Jan 21, 2010 IP
  3. Wp-Mod.Com

    Wp-Mod.Com Peon

    Messages:
    381
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no still the same , what i want is this

    if 2 then show ads 2 , if 4 show ads in 2 and in 4 , if 6 show ads in 2 , 4 and 6 and so on ,

    whereas now it is , if 2 show 2 , if 4 show 2 and 4 , if 6 show 2 and 6 and ,if 8 show 2 and 8
     
    Wp-Mod.Com, Jan 21, 2010 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Hi, I could not get in much depth but let me know of something like below helps..

    
    $loop = get_option('wpmod_ads_number');
    for($i = 1; $i <= $loop; $i++)
    {
    	$image_link = 'wpmod_show_image_' . $i . '_link';
    	$image_src = 'wpmod_show_image_' . $i;
    	$image_title = 'wpmod_show_image_' . $i . '_title';
    	
    	echo '<a href="' . $$image_link . '"><img src="' . $$image_src . '" width="125" height="125" alt="' . $$image_title . '" title="' . $$image_title . '" /></a>';
    	//echo '<br/>';
    }
    
    PHP:
     
    mastermunj, Jan 21, 2010 IP
    Wp-Mod.Com likes this.
  5. Wp-Mod.Com

    Wp-Mod.Com Peon

    Messages:
    381
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    many many thanks your an angel i could never had figured that out :)

     
    Wp-Mod.Com, Jan 21, 2010 IP
  6. hireme

    hireme Member

    Messages:
    58
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #6
    actually the only problem with your first code is the if-elseif.. try using if only for all.. ;)
     
    hireme, Jan 21, 2010 IP