0

I am using a custom post type to manage adverts on a website. There are 3 identical ad spaces on each page, output via WP Query.

Could someone please suggest, on a high level, an approach to show 3 different posts per page load, but not repeat posts shown from previous page (could be sequential)?

So for example, if there were 9 adverts (posts) in the custom post type:

  • User lands on website page > adverts 1, 2 and 3 are visible.
  • User navigates to another page > adverts 4, 5 and 6 are visible.
  • User navigates to a third page > adverts 7, 8, and 9 are visible.
  • User navigates to another page > adverts 1, 2 and 3 are shown again.

I don't need the answer to provide the code, necessarily; just an explanation of how one might approach the solution.

The point of doing this is to make sure each advert gets an (almost) equal number of impressions for each visitor, but I cant use 'orderby' => 'rand' because nCr (n=9,r=3) probability (which is how I've currently implemented it) means that the same adverts can be shown on two successive page loads and the client doesn't want that.

I am considering a JS cookie as the only way to keep a counter and querying the posts via AJAX, but perhaps there is another way?

Many thanks in advance.

1 Answer 1

0

I think that the cookie is the best if not the only solution...

Cookie can be implemented by php or js and is your choiche to choose the right method:

Depending on:

  • the client needs (they have to work also if js is not present?),

  • the number of custom posts and site traffic (they can become a json file in a "special page" precompiled so the server can be lighter...)

PS: remember to study the right solution:

  • what if the post are less than 3?

  • what if they are not dividable by 3? (5 for example)

etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.