totoff Posted February 28, 2015 Posted February 28, 2015 Hello all, I was absent for a while from developing - seems I got rusty in the meantime ... Having weird trouble with trying to redirect a page to its first child. I have the following structure: - /section/ (template A) -- /child 1/ (template B) -- /child 2/ (template B) and so on. Template A has the following conditional: if($page->numChildren) $session->redirect($page->child()->url); However, whenever /section/ is clicked, it redirects to /child 2/ but not to /child 1/. This happens on every section with template A and children. To make this even more weird, the redirect has worked perfectly fine for weeks and the strange behavior occurred today after editing content in the admin. Template A sort settings == none /section/ page sort settings == nothing selected I've tried selector "sort=sort" but it changes nothing (/child 1/ is the oldest page). I've also tried to set child sort order on /section/ to manual-drag-and-drop. Again without success. I'm quite helpless with this and would appreciate any help. Thanks.
LostKobrakai Posted February 28, 2015 Posted February 28, 2015 Does $page->children also show the children in the wrong order? Does explicit sorting work there?
totoff Posted February 28, 2015 Author Posted February 28, 2015 Hi LostKobrakai, thanks for your post. $page->children without selector echoes the correct order. $content2 = $pages->get(1015)->children("sort=-sort"); returns /child 2/ as the last item in the list (that is, the oldest page). However, /child 1/ is definitely older as per its created timestamp ... EDIT: corrected confusion of younger/older
LostKobrakai Posted February 28, 2015 Posted February 28, 2015 I don't know exactly, but does sort=sort not sort by the order of pages are in the pagetree? sort=created would sort by creation date. Also there shouldn't be a problem if children() returns the right order as child() internally calls children() and just returns the first page if there are children. 1
totoff Posted February 28, 2015 Author Posted February 28, 2015 I don't know exactly, but does sort=sort not sort by the order of pages are in the pagetree? Yes, you are right, it does. I was wrong. Also there shouldn't be a problem if children() returns the right order as child() internally calls children() I tried $content2 = $pages->get(1015)->children->first; and it returns /child 1/ (id 1023). However, the problem remains if($page->numChildren) $session->redirect($page->child()->url); still redirects to /child 2/ (id 1024) ...
Nico Knoll Posted February 28, 2015 Posted February 28, 2015 if($page->numChildren) $session->redirect($pages->get(1015)->children->first); why not this way? Or: if($page->numChildren) $session->redirect($page->children->first);
totoff Posted February 28, 2015 Author Posted February 28, 2015 Hi Nico, if($page->numChildren) $session->redirect($page->children->first->url); works. But I would still like to understand why $content2 = $pages->get(1015)->children("sort=-sort"); renders child 2 as child 1 while $content2 = $pages->get(1015)->children("sort=sort"); renders the correct order. I mean, there is something wrong obviously ... $pages->get(1015)->children->first is not applicable as 1015 is just one out of many sections sharing the same problem.
LostKobrakai Posted February 28, 2015 Posted February 28, 2015 Do you mean sort=-sort is not just reverting the order, but mixing it up?
totoff Posted February 28, 2015 Author Posted February 28, 2015 Do you mean sort=-sort is not just reverting the order, but mixing it up? Yes, exactly. $content2 = $pages->get(1015)->children("sort=sort"); renders 1023|1024|1031 which is correct $content2 = $pages->get(1015)->children("sort=-sort"); renders 1031|1023|1024 See what I mean?
Adam Kiss Posted March 1, 2015 Posted March 1, 2015 Is it possible that 1023 and 1024 were created at the same moment? Because in that case, sort=sort acts like sort=created|id and sort=-sort would be sort=-created|id, this your real order would be something like (1023, 1024), 1031 and 1031, (1023, 1024). (This is just a pseudocode, afaik there isn't anything like sort=created|id)
totoff Posted March 2, 2015 Author Posted March 2, 2015 Hi Adam, Is it possible that 1023 and 1024 were created at the same moment? Not according to the timestamp. 1024 was created three minutes later than 1023.
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