Jump to content

Yet another sorting issue about featured and non featured articles


Can
 Share

Recommended Posts

Hola amigos,

I'm a little stuck on this one and I couldn't find any solution so far, which might be my fault but who knows^^

I got a blog with articles having a page field called "props" which lists (checkboxes) my hidden /processwire/page-properties/ tree containing properties like e.g. featured and gallery

Now I want to get all those article pages all sorted -published so descending but featured articles first

before I only used the featured property so sort=-props.name worked but now I'm using gallery prop too but I don't want them to be upfront, too

$normal = $page->children("props!=[name=featured], images.count>0, sort=$sort, limit=$limit");
$articles = $normal->prepend($page->children("props=[name=featured], images.count>0, sort=$sort"));

I also tried featured first then appending "normal" articles, my problem I'm not really able to limit the end result with pagination

the above snippet works but limit is not as expected, I also tried the above without any limit and then doing $articles->find("limit=$limi"); which worked but without showing the pagination..

I know could simplify by using a checkbox inputfield called featured, but I really think it should work using page reference field as it's cleaner in the backend, but maybe I should just do this anyway?!

would be nice to have selectors to be able to sort=[props.name=featured] than sort=-date

or am I missing something here?

saludos Can

Link to comment
Share on other sites

Sadly I don't think it's possible to sort by whether some condition is true, e.g. sort=[props.name=featured]

I think switching to separate checkboxes for each property you may want to sort on would be the easiest solution.

If you want to stick with the Page field and the number of featured articles is likely to always be less than $limit then you could do something like...

$featured = $page->children("props=featured, images.count>0, sort=$sort"); // no sub-selector for props is necessary
$articles = $page->children("images.count>0, sort=$sort, limit=$limit")->filter("id!=$featured");

Then on page 1 of the results you loop over $featured, followed by $articles.

Alternatively I think Paginator by  @LostKobrakai is designed for this kind of scenario but I'm not sure how it works. Maybe he will reply with some tips.

Link to comment
Share on other sites

Thanks for your input Robin,

Because actually it's even more about having one article always at second position (like a banner) I just prepended this one and reorder via css for now.

more advanced sorting would still be great though :D

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...