Php random sort advertisement implementation code. The advertising personnel are very concerned about where the ads will be placed, because this may affect the number of clicks, or even whether they are displayed on the first screen. in fact, this problem can be easily solved. as long as the people who randomly advertise are very concerned about where the ads will be placed, this may affect the number of clicks, or even whether they are displayed on the first screen. this problem can be easily solved, as long as the advertisement is displayed randomly.
How to implement the code? Here I recommend two solutions for randomly displaying advertisements.
Processing at the backend
On the back-end sorting page, store ad nodes in arrays, randomly sort the arrays, and then output the sorted arrays. the reference code (PHP) is as follows:
The code is as follows:
// Store the ad list with arrays
$ Ads = array (''
,''
,''
,''
);
// Random sorting of arrays
Shuffle ($ ads );
// Output the sorted array
$ Html = '';
Foreach ($ ads as $ ad ){
$ Html. = $ ad;
}
Echo $ html;
Let's expand. if I am a webmaster, I have reserved four ad spaces, but now only three are serving. I want to put a "waiting" ad rent link in a vacant ad space, and displayed at the end. what should I do? After sorting, insert the ad leasing link.
The code is as follows:
// Store the ad list with arrays
$ Ads = array (''
,''
,''
);
// Random sorting of arrays
Shuffle ($ ads );
// Output the sorted array
$ Html = '';
Foreach ($ ads as $ ad ){
$ Html. = $ ad;
}
// Add an ad leasing link
$ Html. = '';
Echo $ html;
I use this method to output 125x125 ads, because it is intuitive and reliable and easy to handle. However, if you want to make static pages, we recommend that you use the JS random sorting method.
Processing at the front end
In the back-end, output in the original order and re-order the page by using JavaScript. assume that the HTML segment of the page output advertisement area is as follows.
The code is as follows:
We can use JS to re-sort advertisements. the reference code is as follows:
The code is as follows: