We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1061
    • 81 Posts
    For Evolution you can use this: getParent()
    function getParent($id = -1, $active = 1, $fields = ['id, pagetitle, description, alias, parent'] );

    example:
    $parent = $modx->getParent(55,1,'pagetitle');
    return $parent['pagetitle'];
      • 28881
      • 18 Posts
      Here’s a variation on mrhaw’s using revo:

      $parentID = $modx->resource->get('parent');
      $document = $modx->getObject('modResource',array(
          'id' => $parentID,
         ));
      return $document->get('pagetitle');
        • 17667
        • 108 Posts
        Another option for Revo is to use the getResourceField extra. Then you can use:

        [[getResourceField ? &id=`[[*parent]]` &field=`pagetitle`]]


        And if you want to display the current page’s title if there is no parent use;

        [[getResourceField:ifempty=`[[*pagetitle]]` ? &id=`[[*parent]]` &field=`pagetitle`]]
          • 3749
          • 24,544 Posts
          Quote from: sunwukung at Nov 17, 2010, 11:02 AM

          Here’s a variation on mrhaw’s using revo:

          $parentID = $modx->resource->get('parent');
          $document = $modx->getObject('modResource',array(
              'id' => $parentID,
             ));
          return $document->get('pagetitle');


          Let me tweak that Revo version slightly:

          <?php
          $parentObj = $modx->resource->getOne('Parent');
          return $parentObj->get('pagetitle');
          

            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
            • 20407
            • 82 Posts
            Quote from: lukemcd at Feb 19, 2011, 03:41 AM

            Another option for Revo is to use the getResourceField extra...

            You rock. Exactly what I needed; thank you!
              • 8872
              • 41 Posts
              For my needs I did it this way:
              [[*parent:ne=`0`:then=`Parent page: <a href="[[~[[*parent]]~]]">[[getResourceField? &id=`[[*parent]]`]]</a>`:else=``]]

              If parent exists it will display it, unless the parent is home page (id=0).
                • 42184
                • 27 Posts
                I'm guessing MODX has changed since the previous response to this thread because I can't get it to work. The following does work though:

                Snippet Code

                <?php
                /**
                 * MY_GetPageTitle
                 *
                 * DESCRIPTION
                 *
                 * This snippet returns the title of a page matching an id
                 *
                 * USAGE:
                 *
                 * [[!MY_GetPageTitle? &id=`[[+parent]]`]]
                 */
                
                $page = $modx->getObject('modResource', $id);
                if(!empty($page)) {
                	return $page->get('pagetitle');
                }
                return '';


                Template Code

                [[!MY_GetPageTitle? &id=`[[+parent]]`]]
                  • 3749
                  • 24,544 Posts
                  Simon, your snippet would be much faster and more efficient.
                    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
                    • 42042
                    • 140 Posts
                    Quote from: sunwukung at Nov 17, 2010, 11:02 AM
                    Here's a variation on mrhaw's using revo:

                    $parentID = $modx->resource->get('parent');
                    $document = $modx->getObject('modResource',array(
                        'id' => $parentID,
                       ));
                    return $document->get('pagetitle');

                    Works, thanks man!
                    • Guess Revo changed again:

                      [[!MY_GetPageTitle? &id=`[[+parent]]`]]


                      should now read

                      [[!MY_GetPageTitle? &id=`[[*parent]]`]]


                      Notice the asterisks and plus character preceeding parent