Jump to content

Start array from current


Peter Knight
 Share

Recommended Posts

I have a selector which is pretty simple and just fetches a series of pages except for the current page.

1,2,3,4,5,6,7

When you're on page 1, the output is
2,3,4,5,6,7

When you're on page 2, the output is
1,3,4,5,6,7

$services=$pages->find("template=a-practice-area, id!=$page, sort=sort "); 
foreach($services as $service) {
echo "
<div>...

 

Currently, the array (is that what it's called? starts from the first item (service) in the tree and continues.

I'd now like to start the array from the next item in the array instead always starting at the first.

IE if you were on page 2, the output is
3,4,5,6

IE if you were on page 4, the output is
5,6,7

Looking at the docs, a selector called 'start' is mentioned.

Quote

That selector tells ProcessWire to return 50 (or fewer) results. The starting result is always the first, unless you use the "start" reserved word, i.e.


start=50, limit=50
2

I think this is what I need and have tried the following to no avail

<?php $services=$pages->find("template=a-practice-area, id!=$page, sort=sort, start=$page"); 

Any tips?

 

 

 

Link to comment
Share on other sites

1 hour ago, LostKobrakai said:

Why would there if you need a "current" page to be able to do all of that?

You're right - thank you.

So I adapted my code to use page instead of pages and this modfied version works

 $items = $page->nextAll('template=a-practice-area');
foreach($items as $item) {
echo "

IE if you were on page 4, the output is
5,6,7

Is there a method to restart  the array after it reaches the end so that the output is

5,6,7,1,2,3,4

 

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...