Any way to get a sortable date as a page part?
|
486 posts
|
I’m still wondering if might be possible to do events using page parts. But in order to do that I need the date to be sortable. Is there any way to store a date as a page part and be able to sort by that? |
|
257 posts
|
Hi Ricks, it may be worth exploring the tags system to do this – set out a date structure for the events then do a php sort on the page you’re calling – I’m trying to figure out a way to use a plugin to manage events but am not quite there yet. The plugin is developed up to the stage of having events in the database and an admin plugin to add / edit them. I am hopefully going to release it in November but if you need something now, tagging may be a good step… |
|
486 posts
|
thanks andy. i didn’t think about tags. i’ll check that out. |
|
6 posts
|
I had the same problem, and tags didn’t seem right to me, semantically. Anyway, I cleaned the code up a little and put it in a plugin. It provides the function Example: The main page is “Events”, every event is a direct subpage of “Events” and has a part named “date”, which contains the date of the event in the format “YYYY-MM-DD”.
Let me know if it works for you. |
|
1493 posts
|
Hi Christian – sounds like a great idea! I tried it on a dev site, though … I think I need more documentation! :) When I used
in the parent page, then I got nothing. But when I tried (just guessing):
then all I got “echoed” was |
|
6 posts
|
Oops, sorry. I should have mentioned that the function returns an array of Page objects. Use it just like you would the array returned by |
|
1493 posts
|
Thanks for that! I knew there had to be a One thought for an enhancement: would there be any chance of adding a param to set the display order of the date elements? The “input” is YYYY-MM-DD, of course. It would be nice to display that as dd-mm-yyyy, or “mm dd, yyyy”, or whatever. What do you think? |
|
1493 posts
|
Also, a nice tweak to Christian’s code:
That gets you just a listing, with date, of the “event” with a click-through to its own page. This is lotsa fun! :) Also, (d’oh!) I realized I needed to have the page |
|
6 posts
|
Cool that you find it useful! As for the display order, you have to munge it by hand. One way to get at the parts of the date is |
|
486 posts
|
thanks christian. i’ll try out what you’ve got soon as i get a chance. |
|
10 posts
|
Is there a way to exclude certain pages from a given query, based on a part? |
|
1493 posts
|
In the example above, the plugin is looking for a “date” page-part. If one of the “children” pages does not have that part, then it is omitted from the the |
|
4 posts
|
Help! I think I’m trying to make this harder than it is. I want sort children by title or slug in ascending order. How do I go about doing that? Thanks! |
|
1493 posts
|
@cdembinski – I think it is easier than it looks. In the documentation, you get the impression that you can only order on date elements when displaying a list of sub-pages. In fact, you can also use
will sort by the Title of the page in ascending order. But you could equally alter that second line to read:
To sort by slug in descending order, etc. Have a look at the “page” table in phpMyAdmin to see the other values you could use. Hope that helps! [And documentation updated!] |
|
4 posts
|
Thanks for the response David. However, if I copy and paste this into my page I get nothing. Does it matter if the “parent” page I’m putting this into is a child itself? Here’s what I’m trying to do. I’m setting up a directory, where directory is my “home” page. Category pages are set up as children pages of the directory. I want to set the individual listings for each category up as a child of the category so that they will be sorted alphabetically as I continue to add new listings. Example: A. Accessories (Child) 1. ABC Shop Listing (Child of Accessories) 2. DEF Shop Listing (Child of Accessories) Hope this makes sense. I do realize that I will have to echo the content of the page and not just the title. Thanks, |
|
1493 posts
|
Hi Chris – If you put the code from my previous post in the “body” of your “A. Accessories” page (from your example), you should get a listing like:
where those are also linked to the “ABC” and “DEF” pages, in alphabetical order, if they are “children” to the “Accessories” page. Do you have the site live online? or are you developing on “localhost”? If we can take a look at what you are attempting, the solutions might also be more helpful! |
|
4 posts
|
Here’s a link to the page that I pasted the code into. http://www.shopindieonline.com/indi/?mens-shop.html This page has two hidden child pages. |
|
1493 posts
|
And if these are the two you want listed, that explains the problem! Have a look at the docs on page status definitions. “Hidden” pages are not found by the If you want the pages to be “hidden”, you need to use a variation on the code above:
The additional I see you have a lot of “categories”, though. With this technique, you will need to put that code in every “category” page. I suppose there are other options, but it looks like all your pages are created now so I don’t think any of the “time savers” will now save you time! Hope that works! |
|
4 posts
|
Thanks David! You’re fabulous!! Guess I need to go back and read the documentation more carefully. |