johnstephens Posted October 23, 2020 Share Posted October 23, 2020 Hi! 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 = $topic1->id ? 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 More sharing options...
johnstephens Posted October 23, 2020 Author Share Posted October 23, 2020 Of course, the simplest solution to my specific issue was to use page()->siblings() instead of rootParent()->children(). Fixed. 1 Link to comment Share on other sites More sharing options...
kongondo Posted October 23, 2020 Share Posted October 23, 2020 I marked your topic (title) as solved ?. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now