Jump to content
totoff

Custom sort order for pages

Recommended Posts

Hi all,

I wonder if PW allows for a custom sort order of pages? I would like to render my page tree custom sorted for a mobile menu, e.g. not in "reverse sort order" or "sorted by date" and so on but completely customized.

My current page tree in the admin looks as follows (numbers are page ids):

/

|- page 1006

|- page 1058

|- page 1062

But for my mobile menu I try to render the following order:

/

|- 1062

|- 1006

|- 1058

$entries = $pages->get("id=1|1006|1058|1062, sort=??");

Any ideas how to achieve this?

Many thanks!

Share this post


Link to post
Share on other sites

If you have set the sort order to manually in the childrens parent site, you can use "sort=sort" or "sort=-sort" in the selector.

(Hope this is what you are asking for??)

Share this post


Link to post
Share on other sites

Hello Horst,

unfortunately this is not what I meant. The page tree in the admin needs to remain as it is (as it makes for the desktop navigation). I need a custom order ("sorting") only for the mobile navigation.

In other words: I need to render the pages in a custom order different to what I have in the admin.

Difficult to explain in English. Hope one can get it ...

Share this post


Link to post
Share on other sites

I would create a multiple select page field on the template that you are using to control your navigation. Either point the page field to the parent of your navigational elements or use a asm field and filter by template. Then instead of performing your find on the pages you will just load the field. 

<?php 

$navigation_elements = $pages->get('/setting-page/')->navigation;

foreach($navigation_elements as $elem){
  //nav code here
}

?>
  • Like 5

Share this post


Link to post
Share on other sites

Let say you have these pages in your tree:

Products (1005)

|- page 1006

|- page 1058
|- page 1062
 

You could add a field of the type Page (FieldtypePage) with a name "mobile_sort" or something alike. make sure you can select multiple pages, and it will list the children from the Products (1005) page (or whatever your parent page is named).

Then add this field to the Products page template. Next edit the Product page and select all the children and sort them accordingly for mobile.

You could then create a navigation for your mobile listing all pages attached to the "mobile_sort" field.

Another way i think will work is to use the sorting of the mobile_sort field in your selector. 

sort=mobile_sort.sort
  • Like 5

Share this post


Link to post
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.

  • Similar Content

    • By snck
      Hi there,
      I have a problem constructing a selector that finds all pages that refer to pages with a specific template.
      I have pages using an event template and I want to show events based on a specific context. In this example I want to filter the results and only show event pages that relate to a specific template (exhibitions) in their page field related_pages.
      What I tried:
      $events = $pages->find("template=event, related_pages.template.name=exhibition"); Unfortunately it does not work (0 results).
      Same with this:
      $events = $pages->find("template=event, related_pages=[template.name=exhibition]"); At the moment I am helping myself with the following lines, but I have a strong feeling that there is a more efficient solution:
      $events = $pages->find("template=event"); foreach($events as $event){ if(!count($event->related_pages->find("template=exhibition"))){ $events->remove($event); } }  
      I really hope that one of you can help me out.
      Thanks in advance!
      Flo
    • By quickjeff
      Hi Guys, 
      I have been debugging a site for the last 2 hours and cannot solve the issue. 
      I have a site running on 3.0.148. 
      I installed the Kongondo Blog module and was updating the templates to include the website style. 
      Once everything was set and done, I checked the page tree to see an error appear. 
      Template must be assigned a name before 'filename' can be accessed
      The same error appears in templates. 
      Debugging Steps
      I checked the templates in the server to ensure I didnt accidentally delete the namespace.  Deleted cache in browser and server under assets Still no go. 
      Any help is appreciated. 
      Thanks! 
    • By Kiwi Chris
      The selector in the following code included in a template is returning nothing, however if I take out the compId.resultsdate<={$today} bit, it works fine, although obviously not filtered on the date field.
      $today = strtotime(date('Y-m-d')); $setImages = $pages->find("template=competitionImage, compId={$page->id}, compId.resultsdate<={$today}, compSubject.name=s, imageRating.title=Merit|Honours,check_access=0"); Here's the results of an example from Tracey Debugger
      templates_id=79, resultsdate<=1587729600, status<2048   SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_resultsdate AS field_resultsdate ON field_resultsdate.pages_id=pages.id AND (((field_resultsdate.data<='2020-04-25 00:00:00' ) )) WHERE (pages.templates_id=79) AND (pages.status<2048) GROUP BY pages.id Over in my ready.php I have inside a hook that refers directly to the page template that's used for the pages in the page field above:
      $today = strtotime(date('Y-m-d')) $event->return = $event->pages->find("template=competition,eventEnd>={$today},eventStart<={$today}"); In this case the filtering on date fields (albeit different ones) works fine. Can anyone suggest why the filter on the date subfield of the page field isn't working?
      Just to confirm, I do have a date value in the field, and it is a date before today. 🙂
      The problem may be something blatantly obvious, but I can't for the life of me figure out why the selector is returning no results when I include the date filter.
    • By opalepatrick
      Hi, trying to order pages by modified date, date. I can do 'sort=-date_modified, sort=-date' but that will always put the modified date first regardless of actual date order. I just want to coalesce the two fields and sort. Any ideas would be appreciated.
    • By Spyros
      Hello
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      PS 
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
×
×
  • Create New...