Jump to content

spos

Members
  • Posts

    4
  • Joined

  • Last visited

Recent Profile Visitors

1,269 profile views

spos's Achievements

Newbie

Newbie (2/6)

0

Reputation

  1. Fixed it and cleaned it up this morning. Here's the function should anyone have any ideas for streamlining it or wanders across this thread searching for a possible solution: function natural_sort_pagearray($unsorted_array) { $temp_array = array(); foreach($unsorted_array as $page) { $temp_array[] = $page; } usort($temp_array, function($a, $b) { return strnatcmp($a->name, $b->name); }); $sorted_array = new PageArray(); $sorted_array->import($temp_array); return $sorted_array; }
  2. I'm trying to sort a PageArray by $page->name and because there are digits in the name I need to use a natural sort (like php's natsort()). I've gone through the process outlined in https://processwire.com/talk/topic/3392-emulate-natsort/ but I must be missing something because I can't get it to work at all. I then tried a different way and created an array of the page names, used natsort and implode to give me a correctly sorted string to use in a selector. I then do $output = $pages->find("name=$selector_text"); and the correct pages are returned but they're not in the same order as in my selector string. I've only found a couple mentions of natural sorting on the forums so I must be missing something simple but I just can't put my finger on it.
  3. I've been away from a few days and only just came back to this but thank you both, I've been having a play this afternoon and the concepts are falling into place.
  4. I'm trying to build a fairly simple site as an intro to processwire. Currently on my to-do list is to have an "our customers" page with a list of testimonials, and also to have a random testimonial snippet picked from this list in a sidebar on various other pages. So, I created a repeater field "testimonials" comprising testimonial_body, testimonial_summary and testimonial_name (the testimonial_summary is just a few choice words for the sidebar). Created a template "testimonial_list.php" and assigned the testimonials repeater field to it then made a page "our-customers" and gave it the template "testimonial_list". So, I've got an /our-customers/ page that lists the testimonials: foreach($page->testimonials as $testimonial) { echo "<blockquote><p>{$testimonial->testimonial_body}</p>"; echo "<small>{$testimonial->testimonial_customer}</small></blockquote> "; echo "<hr>"; } All good so far, but now I'd like to add pagination. However, after reading the selectors and pagination API docs I'm afraid I have no idea how to proceed. Should I even be using repeater fields for this? They weren't enabled by default so I'm thinking perhaps I should be using a separate page for each testimonial. I'm having a hard time figuring out how pages, templates, fields relate to each other.
×
×
  • Create New...