We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5546
    • 23 Posts
    i feel like this is a dumb question - but i am not having any luck in searching for an answer so here it goes. i have a parent document with a child. is there a way i can put a link in my parent document to its child? i.e. <a href="link_to_child">link</a>

    i’ve been looking through wayfinder and i don’t see how it can help solve this problem. i’m pretty new to modx and all it has to offer, so maybe i am searching in the wrong place.

    any help is greatly appreciated. thank you!!
      • 3749
      • 24,544 Posts
      A document can have many children, so there’s no generic way to do it. If you know the ID of the child, you can do it with a simple link tag:

      Evolution:

      <a href="[~12~]">Child</a>


      Revolution:

      <a href="[[~12]]">Child</a>


      Change 12 to the actual ID of the child resource.

      If your sure the documents will only have one child, you can do it with a snippet. In revolution it would be something like this:

      <a href=[[!ChildLink]]>Child</a>


      <?php
      /* ChildLink snippet */
      
      $child = $modx->getObject('modResource', array('published'=>'1', 'deleted'=>'0','parent'=>$modx->resource->get('id') ));
      return $child->get('id');
      
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 5546
        • 23 Posts
        that was fast! so i tried this out and had to make a modification. i guess the way i have set things up may be more complicated than i thought. basically i have a page and in that page i display that parent’s children using getResources. each of those children will have one child as well.

        so i changed the snippet code to this:

        <?php
        /* ChildLink snippet */
        
        $parent= $modx->getObject('modResource', array('published'=>'1', 'deleted'=>'0','parent'=>$modx->resource->get('id') ));
        $child = $modx->getObject('modResource', array('published'=>'1', 'deleted'=>'0','parent'=>$parent->get('id') ));
        return $child->get('id');


        it seems to work except that each of the links is the same id. does that make sense? is it even possible to do what i am trying to do?
          • 3749
          • 24,544 Posts
          I think you might be better off trying to use Wayfinder do to that rather than getResources. It’s designed to produce the tree as a set of links in a list.

          Try using just this (replace 12 with the appropriate top-level parent):

          [[!Wayfinder? &startId=`12`]]


            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 5546
            • 23 Posts
            ok i spend some time trying to get wayfinder to work with it...it isn’t that it didn’t work, but it messed up some of my other stuff. so..for now i need to figure out a different way to structure my pages/content so i can do this properly. thank you so much for your help. i really appreciate it!!
              • 17705
              • 501 Posts
              Quote from: BobRay at Nov 01, 2010, 01:31 AM
              If your sure the documents will only have one child, you can do it with a snippet. In revolution it would be something like this:

              <a href=[[!ChildLink]]>Child</a>


              <?php
              /* ChildLink snippet */
              
              $child = $modx->getObject('modResource', array('published'=>'1', 'deleted'=>'0','parent'=>$modx->resource->get('id') ));
              return $child->get('id');
              


              In a future site I will have that scheme
              A detail in a child document... so I want to automagically generate those links, as well as parent link in child, where I will use something like <a href="[~[*parent*]~]">My Parent</a>

              But... wich will be the link to child snippet code to work in evolution?

              thanks, and sorry for the bad english smiley
                • 3749
                • 24,544 Posts
                It’s more complicated in Evolution and I’m afraid I can’t remember how to do it. Someone else will have to answer.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting