We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6434
    • 3 Posts
    Hi all,

    I’m writing a snippet that builds the main navigation for a website - one of the navigation items is a weblink (the rest are normal resources).

    The code I’ve written works for modResource but not modWebLink (which makes sense given they’re different) but I’m wondering what the best way is to get the modWebLink as well as the modResource - do I have to do 2 separate queries or am I missing something in the below that will do this for me?

    // Get level 2 parents
    $criteria = $modx->newQuery('modResource', array('parent' => 0));
    $criteria->where(array('published'=>true)); // Only published docs
    $criteria->where(array('deleted'=>false)); // Only docs that haven't been deleted
    $criteria->where(array('hidemenu'=>false)); // Only docs that aren't hidden from the main menu
    $criteria->select(array('id', 'menutitle', 'pagetitle')); // We want these fields
    $criteria->sortby('modResource.menuindex', 'ASC'); // Order by menuindex ASC
    $parents = $modx->getCollection('modResource', $criteria); // Execute the query
    


    Many thanks for you help,
    Dan
      - Dan
      • 22303 MODX Staff
      • 10,725 Posts
      That query should retrieve all Resources that match that criteria, as an instance of the indicated class_key. IOW, it should work fine for any derivative modResource. Nothing is ever a modResource, but rather a derivative class, either modDocument, modStaticResource, modWebLink or modSymLink. Other derivative modResource classes can be developed, as well.