Jump to content

Matte85

Members
  • Posts

    5
  • Joined

  • Last visited

Matte85's Achievements

Newbie

Newbie (2/6)

0

Reputation

  1. Oh actually! Just saw your last comment there: That could work for this case! I did not realise you could use conditional statements like that for the selector. Will update once I get a chance to try that out! Thanks in advance Robin, I think this might cut it!
  2. This probably depends on how you set up the multi language site, but I set it up so that you have pages with duplicates of each field for each available language. For example, a page could normally have one title field and one text area, which in a multi language site with 3 languages would mean you have three fields for title and three text areas for the page, that is one for each language. It might be that some pages lack a translation in a certain language. That is, the page would exist, but for the particular language the fields would be empty. If you want to iterate through these pages you need to set up a loop that checks if a translation exists for each page, and if it doesn't exist, skip to the next page amongst its siblings. Now, the complexity comes of the fact that there might be a variable amount of siblings (they might be blog posts for example) where it is not known which texts have translations in which languages. So, if you want to display e.g. the 5 most recent posts in any given language, "limit=5" wouldn't cut it, since it would fetch the 5 first pages, regardless if they have translations or not. Therefore ->eq($i) is a better solution seeing how this one handles only one page at a time. As such a loop can be constructed that would include e.g. the 5 latest blog posts that indeed have been translated. However, since ->eq() relies on ->children(), it means the backend process needs to first include all siblings in the array (unlike when using "limit=$limit"), which wouldn't be optimal, especially if there are a lot of siblings. In practical terms, I'm not sure if this actually can cause issues even with moderate traffic. But, it would be interesting to see if there is an optimal way to do this that I haven't thought of.
  3. Thanks Robin, but the issue with the solution you are suggesting wouldn't work if there is a variable number of children. This can be the case when using multi-language sites where e.g. a blog post might or might not have a translation. If you then wish to return a set number of blog posts, you would end up short for the ones that lack translations. The only solutions I have come up with for this issue is to either first retrieve all children and then iterate through them, like so: $allChildren = $parent->children(); foreach( $allChildren as $child... ...which has the drawback that it first retrieves all children which might be a heavy process if there are many pages. The other option is indeed the one presented in my first post, which I have my doubts about too. Thanks!
  4. Hi, In the $page documentation we can read: Would the following then retrieve the full children array and only then pick the desired page: $p->children()->eq($i) My concern is using the above in conjunction with "while", like below: while( $i++ < $limit){ $child = $parent->children()->eq($i); ... Thanks!
  5. Hi, I have encountered the following problem in the otherwise magnificent CMS ProcessWire: I'm sorting pages according to: "$page->children("sort=...". This is principally working fine, but the problem occurs when values like the following are returned: "10,4m3; 10m3; 8m3...". ProcessWire interprets them as text, which means that it thinks that e.g. "8m3" is greater than "10m3" seeing how the earlier begins on a greater number. Does anyone have any ideas how I could work around this issue, and indeed get PW to sort the values in the following order: "8m3; 10m3; 10,5m3...". Thanks!
×
×
  • Create New...