Jump to content

Unique set of links per page


floridaDev
 Share

Recommended Posts

I have 2000 pages. On each page I would like to display 20 links to the other 2000 pages. Each page cannot have the same set of links as another page. I'm trying to come up with a solution where my team doesn't have to manually put in 20 links for these pages. What I had in mind is using the selector below to grab the next 20 links and so fourth..

$page->nextAll($selector, $siblings)

Does this seem like a good PW method? My second option was to just query the DB directly and grab links in sets of 20.

 

Thanks, 

Link to comment
Share on other sites

If each page is going to have 20 links but cannot have the same set of links .... so some pages will have duplicate links but not all 20 duplicates or identical to another page?

I haven't used nextAll so I don't know what it does exactly but I think you could use something like the following.

wire(pages)->find("path=/path to you pages/")->children()[0]->findRandom(20);

The children()[0] may not be necessary .. all depends on your page structure.

The code snippet is from 1 of the libraries I wrote to generate some random links.
 

Now, there is a small chance that this code might return the same 20 links in some scenarios.

If this is still a strict requirement, you're going to have to store the pages in some data structure like a hash table, array etc and do a membership test after you generate these links for a page.

Alternatively, you could come up with some unique hashing algorithm for the 20 links so you could store 1 hash value against the page and do a membership test instead if you do not wish to store 20 links per page.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...