Jump to content

[SOLVED] Exclude a page from pagearray, before applying limit


Recommended Posts


I'm trying to create a list of related pages to display on the current page.

First, I'm setting a variable with the first element of the "topics" page reference field, like so:

$topic1 = page()->if('topics', function() {
    return page()->topics->first();
}, false);

Then, I want to check all the sibling pages and gather those who have the same topic. This code works, but the result will include the current page in the results.

$related_articles =
        ? page()->rootParent()->children("topics=$topic1, sort=-datePublished, limit=3")
        : new PageArray();

I can remove the current page by appending the remove method…

page()->rootParent()->children("topics=$topic1, sort=-datePublished, limit=3")->remove(page())

…but that sometimes results in the list producing fewer results than the limit, even when there are more pages tagged with the same topic beyond the "limit" offset.

What I'd like to do is exclude the current page first, and then set the limit.

Thanks in advance for any guidance you can offer!

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...