Jump to content

Sort search result (selector) by template


asbjorn
 Share

Recommended Posts

I have a question on how to group search results by template, with pages sorted alphabetical (as standard) in each group.

I have a film blog running ProcessWire. It has lots of posts, ratings, categories, ratings, directors, actors and tags, my search result is getting crowded by all this pages after a while. These pages have different templates. Until now I have had badges with the template label by their title in the search result.

I am wondering if there's a simple way of coding it to group the search result, kind of like how IMDb does it: Titles are grouped first, then names second. Like this.

To illustrate, here's a part of my structure, template name in brackets:

---

Main (home)

   Blog (posts)

      Movie 1 (post)

      Movie 2

   Actor (actors)

      Actor 1 (actor)

      Actor 2

   Director (directors)

      Director 1 (director)

      Director 2

   Tag (tags)

      Tag 1 (tag)

      Tag 2

---

And here's how I would want my search result to show, e.g. if all these pages where to mention Tom Hanks somehow:

---

Movies:

  • Movie 1
  • Movie 2

Directors:

  • Director 1
  • Director 2

Tags:

  • Tag 1
  • Tag 2

Actors:

  • Actor 1
  • Actor 2

---

I am in a learning process, and I am sure there are other problems that will appear when considering usability. Limits within groups, etc. But for now this is a way of sorting that I might also want to use elsewhere later on.

Whereas I have headings and results in separate lists.

(PS: I have read a couple of posts on group sorting based on parent ID, but none of them was exactly what I was looking for.)

Link to comment
Share on other sites

"sort=template, sort=title" in the selector?

Thanks, that part is clear, but I would like to have headings for each group, and have the results in each group wrapped in UL-tags. I have updated my post to reflect this with bold headers and bullet points.

Link to comment
Share on other sites


$parts = array(

"Movies" => "movie",

"Directors" => "directors"

);

foreach($parts as $title => $template){

$results = $pages->find("template=$template, …");

echo "<h2>$title</h2>";

echo "<ul>";

foreach($results as $result){

echo "<li>$result->title</li>";

}

echo "</ul>";

}

  • Like 2
Link to comment
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
 Share

×
×
  • Create New...