We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33982 ☆ A M B ☆
    • 476 Posts
    So I’m working on a project that requires me to return a different value on a page depending on how many Published children are in a container. What I’ve done is made some modifications from this very helpful posting:

    http://modxcms.com/forums/index.php/topic,25856.0.html

    So I modified the PHP given on the previous posting to this:

    <?php
    // initialize and get the number of children for a particular parent
    $childCount = 1;
    $children = $modx->getChildIds($parent, $depth);
    // determines whether childCount and children are equal to each other
    if ($childCount == count($children))
    // If childCount and children do have the same value of 1, then return the following Ditto here
    echo "[[Ditto? &startID=`71` &tpl=`utilities_listings_tpl` &summarize=`1000` &sortDir=`ASC` &depth=`1` &sortBy=`pagetitle`]]";
    // But if children are more than 1, return the following below
    else
    echo "[[Ditto? &startID=`71` &tpl=`utilities_quicklinks_tpl` &summarize=`1000` &sortDir=`ASC` &depth=`1` &sortBy=`pagetitle`]]


    <hr />
    [[Ditto? &startID=`71` &tpl=`utilities_listings_tpl` &summarize=`1000` &sortDir=`ASC` &depth=`1` &sortBy=`pagetitle`]]";
    ?>
    Honestly I’ve touched PHP coding maybe 2 or 3 times in my life, but I somehow manage to use MODx all the time smiley

    So here’s my dilemma: while the coding works great when there is only 1 child document and no unpublished child documents, the moment you have 1 or more unpublished child documents (which will likely happen in the operation of this website), it results in the "else" statement which I’m trying to avoid. So how do I modify the PHP to output only the number of published children instead of just the number of children? My goal is that if there is only 1 published document under the parent (even though there maybe multiple unpublished documents), I want the first echo statement to be true, not the "else" statement.

    Again, I’ve never really touched PHP before, so any suggestions to this ignorant PHP guy would be appreciated. Thanks!
      Precision Web Development ... SmashStack.com
      • 29635
      • 361 Posts
      Try getDocumentChildren rather than getChildIds, and remove the $depth...
      $children = $modx-> getDocumentChildren($parent);

      Not sure but worth a shot.
        Need MODx Ecommerce? Try FoxyCart!
        • 33982 ☆ A M B ☆
        • 476 Posts
        Perfect...that did it...thanks!
          Precision Web Development ... SmashStack.com