I'm trying to get the ad rotator wp plugin to work by the line order instead of it being random.. can any php expert help me out? here is the orignal code <?php function getad($ad = '') { $ad = trim($ad); if(strlen($ad) > 0) { $ad = ABSPATH . "wp-content/" . $ad . '.txt'; if(file_exists($ad)) { $ads = file($ad); return $ads[rand(0, sizeof($ads)-1)]; } } } ?> PHP: and this is the modfied one but it dosen't move onto the next line.. <?php function getad($ad = '') { $ad = trim($ad); if(strlen($ad) > 0) { $ad = ABSPATH . "wp-content/" . $ad . '.txt'; if(file_exists($ad)) { $ads = file($ad); //$adscnt = count($ads); foreach($ads as $linenum => $line) { return $line; } } } } ?> PHP: I'm sure it's something simple but no idea since I'm clueless when it comes to php. appreciate any help with this.
try <?php $_SESSION['current_ad'] = 0; function getad($ad = '') { $ad = trim($ad); if(strlen($ad) > 0) { $ad = ABSPATH . "wp-content/" . $ad . '.txt'; if(file_exists($ad)) { $ads = file($ad); $i = $_SESSION['current_ad']; $_SESSION['current_ad']++; return $ads[$i]; } } } ?> PHP: However, you must have sessions enabled in your code.
just try the code I given first. If you see any errors regarding session, you will have to add session_start(); PHP: at the very top of your page (ie. header), after the <?php.
well, forget about the sessions. now try these codes: <?php $_COOKIE['current_ad'] = 0; function getad($ad = '') { $ad = trim($ad); if(strlen($ad) > 0) { $ad = ABSPATH . "wp-content/" . $ad . '.txt'; if(file_exists($ad)) { $ads = file($ad); $i = $_COOKIE['current_ad']; $_COOKIE['current_ad']++; return $ads[$i]; } } } ?> PHP: don't forget to remove the session_start(); to avoid whitescreen
the 2nd code loads only the first line with out rotating to the other lines.. Thanks I Appreciate your help.