We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I think you should simplify and just use getCollection(); in order to use getMany() like that, you have to manually join the tables atm (though this is changing in a future release):
    <?php
    $firstcriteria = $modx->newQuery('modResource');
    $firstcriteria->where(array(
       'parent' => '3',
    ));
    $firstcriteria->sortby('pagetitle','ASC');
    $firstlijst = $modx->getCollection('modResource', $firstcriteria);
    $first="parents:";
    foreach ($firstlijst as $firsteen){
    	 $first=$first."<a href=\"".$modx->makeUrl($firsteen->get('id'))."\">".$firsteen->get('pagetitle')."</a> ";
    }
    return $first;
    ?>


    <?php
    $lastcriteria = $modx->newQuery('modResource');	
    $lastcriteria->where(array('parent' => '5',));
    $lastcriteria->sortby('pagetitle','ASC');	
    $lastlijst = $modx->getCollection('modResource', $lastcriteria);
    $last="children:";
    foreach ($lastlijst as $lasteen){
    	 $last=$last."<a href=\"".$modx->makeUrl($lasteen->get('id'))."\">".$lasteen->get('pagetitle')."</a> ";
    }
    return $last;
    ?>

      • 7575
      • 85 Posts
      tnx a lot opengeek!

      I guess I don’t understand how getMany works then.
      with getCollection it was easy!

      if anyone wants to see them:($categorie is a TV)
      shows the children or the bottom layer
      <?php
      if ($categorie<>0){
      	//get current id of the current page to get the children
      	$currentResource = $modx->resource;
      	$currentid=$currentResource->get('id');
      
      	//get the children
      	$lastcriteria = $modx->newQuery('modResource');	
      	$lastcriteria->where(array('parent' => $currentid,));
      	$lastcriteria->sortby('pagetitle','ASC');	
      	$lastlijst = $modx->getCollection('modResource', $lastcriteria);
      	
      	if (count($lastlijst)<>0){
      		$last=$currentResource->get('pagetitle').": ";
      		foreach ($lastlijst as $lasteen){
      			 $last=$last."<a href=\"".$modx->makeUrl($lasteen->get('id'))."\">".$lasteen->get('pagetitle')."</a> ";
      		}
      	}
      	else{
      		//zoek de parent van de huidige pagina en toon daarvan de kinderen
      		$parentResource = $currentResource->getOne('Parent');
      		$parentid=$parentResource->get('id');
      		
      		$lastcriteria = $modx->newQuery('modResource');	
      		$lastcriteria->where(array('parent' => $parentid,));
      		$lastcriteria->sortby('pagetitle','ASC');	
      		$lastlijst = $modx->getCollection('modResource', $lastcriteria);
      		foreach ($lastlijst as $lasteen){
      			 $last=$last."<a href=\"".$modx->makeUrl($lasteen->get('id'))."\">".$lasteen->get('pagetitle')."</a> ";
      		}
      	}
      	return $last;
      }
      ?>

      shows the parents or the top layer
      <?php
      if ($categorie<>0){
      	$currentResource = $modx->resource;
      	$parentid=$currentResource->get('parent');
      	if (isset($parentid)){
      		$parentResource = $modx->getObject('modResource',array(
              'id' =>$parentid));
      		if (isset($parentResource)){
      			$secondparentid=$parentResource->get('parent');
      			if (isset($secondparentid)){
      				$secondparentResource = $modx->getObject('modResource',array(
      				'id' =>$secondparentid));
      				if (isset($secondparentResource)){
      					$tv = $modx->getObject('modTemplateVar',array('name'=>'categorie'));
      					if ($tv->renderOutput($parentResource->get('id'))<>0){
      						$kinderenvan=$secondparentid;
      						$first=$first.$secondparentResource->get('pagetitle').": ";;
      					}
      					else {$first=$first."Categorieën : ";$kinderenvan=3;}
      				}
      				else {$first=$first."Categorieën : ";$kinderenvan=3;}
      			}
      			else{$first=$first."Categorieën : ";$kinderenvan=3;}
      		}
      		else{$first=$first."Categorieën : ";$kinderenvan=3;}
      	}
      	else{$first=$first."Categorieën : ";$kinderenvan=3;}
      }
      else{$first=$first."Categorieën : ";$kinderenvan=3;}
      
      $firstcriteria = $modx->newQuery('modResource');
      $firstcriteria->where(array(
         'parent' => $kinderenvan,
      ));
      $firstcriteria->sortby('pagetitle','ASC');
      $firstlijst = $modx->getCollection('modResource', $firstcriteria);
      foreach ($firstlijst as $firsteen){
      	 $first=$first."<a href=\"".$modx->makeUrl($firsteen->get('id'))."\">".$firsteen->get('pagetitle')."</a> ";
      }
      return $first;
      ?>


      I guess they are not the best way,
      but they work!
        www.tornooi.net online database for (sport) events in dutch.
        To be redesigned, rewritten to modx with multiple languages...
        ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.