A
A
Alexander Ivanov2017-05-13 13:09:04
PHP
Alexander Ivanov, 2017-05-13 13:09:04

How to display only parents of resources through pdoTools and is it possible?


So I came up with a list like:
  1. pillows
  2. sofas
  3. pillows
  4. pillows

And I want it like this:
  1. pillows
  2. sofas

Maybe someone has already experienced this?
________________________
In the resource, the values ​​are always different, something like this &resources=`` - this snippet displays the resources I need, as an option I can write another one, but maybe you can just exclude duplicate categories in pdoT or only display their categories?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2017-05-13
@cimonlebedev

I had to write a snippet, maybe someone needs it:

<?php
//
if(!empty($resources)){
  $resources = explode(",",$resources);
  $arr = [];
  foreach($resources as $id){
    $parentIds = $modx->getParentIds($id, 10, array('context' => 'web'));
    $arr[] = $parentIds[0];
  }
  $arr = array_unique($arr);
  $arr = implode(",",$arr);
  return $arr;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question