Random news feed and ad space shuffle

Daniel DeSouza Posted in Technical Support 7 years ago

Hi Support team,
I want to keep the content on the news feed fresh and rotating, can i somehow get the news feed to shuffle so it's not the same order all of the time? and i want the ad space to do the same, so if there are many ads, thy can shuffle positions so that they all can be close to the top.Is there a way to do it smartly where the newer news or post are to the top and a few posts below shuffle? Only on the news feed, but the ad space can shuffle randomly!

Replies
bb Daniel DeSouza Replied 7 years ago

BTW: the getAds() function i cannot locate it in the Classes folder. Where might i find it?

bb Daniel DeSouza Replied 7 years ago

To Z-Man and Roger,
thanks guys for the solution. This will bring great value to my site and everyone's oSSN site as well.
Many Thanks

German Michael Zülsdorff Replied 7 years ago

@Daniel
Use the code as provided by Roger:
simply add the line $this->order_by = "rand()"; to the getAds() function of your site as shown below.

(Meanwhile I made a pull request to have this change merged to the next Ossn release)

@Roger
I can't confirm getting static ads with cache enabled.
In fact the current Ossn caching mechanism stores CSS and Javascripts, only. You may have a look into your own /cache subdirectory: You won't find any html stuff there.

That's why I have no idea what is causing the same static order at your site and would need the url to verify.

German Michael Zülsdorff Replied 7 years ago

Thanks, for refreshing by brain, Roger - and sorry for causing confusion.
( I'd better stop answering questions at 2:00 AM 😴
Actually I still had this fix from September running on my development site - but I was looking at the official 4.6 code on Github on posting last night. )

As for caching:
At first sight, cache shouldn't be involved here - but I'll set up another site with a clean 4.6 Ossn to verify and come back later...

us Roger Ghostraven Replied 7 years ago

I did some more testing with the fix I posted. It only works if cache is turned off. If it's turned on it randomly shuffles the ads on the first visit but then it doesn't afterwards. The order stays static.

us Roger Ghostraven Replied 7 years ago

ZMan,
You helped me with this problem in the past. You can edit OSSNAds.php in the Classes folder to this:

    public function getAds() {
    $this->owner_guid = 1;
    $this->type = 'site';
    $this->subtype = 'ossnads';
    $this->order_by = "rand()";
    return $this->getObjectByOwner();
}

And it will randomize the order of the ads. We worked on it in this thread:
OSSN Ad Order

German Michael Zülsdorff Replied 7 years ago

Hmmm ... honestly I'm a little irritated at this point:
Since we don't pass an 'ORDERED_BY' parameter to the getAds() function, all ad records should appear in random order by default anyway.

And they really do (at least on my newblue site.) I have 2 ads (one with the 8 inch floppy, and the other one with the game board.) And some times the floppy appears on top, and some times the other ad. Of course, a 50/50 change is not guaranteed this way, but in fact there's no hardcoded ordering involved here.

Just try to refresh your page several times.

bb Daniel DeSouza Replied 7 years ago

Thanks for your input Z-Man and Jeff:

Why i also suggested that the news feed also be randomly shuffled, is because Facebook does something similar (not sure exactly how they do it) so that when users get a chance to see posts that they may have missed in the previous day after the new posts of the day. In any case it was just a suggestion.
So how do i get the ad space shuffled?

German Michael Zülsdorff Replied 7 years ago

I would agree to the ads part: Shuffling makes sense here.

But on the news feed? I'm used to remember what was shown on top last time and 'store' that sight in my brain. Hence to me it would feel really confusing to find supposedly new stuff on top next time which in the end appears to be outdated when I have a closer look.

Besides of that: We have to keep database usage and performance in mind. Doing some extra fetches here, just in order to get some older records mixed in isn't really meant to speed things up. :)