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

    To solve my previous question i just need to add the creation and the returns (that's what I can't figure out how to do) in the pdoNeighbors snippet;

    This snippets get exactly what I need ($prev and $next ) that contains early in its code the values of the previous and next sibling pages ID
    I really need to get those ids returned as placeholders like +prev_id and +next_id for instance.


    Can someone tell me how to do this, as I'wont desperately never be enough PHP friendly...

    Thanks a lot.


      • 4172
      • 5,888 Posts
      I think, this is what you want:

      <?php
      //[[getNext? &field=`longtitle` &menueindex=`[[+menuindex]]` &parent=`[[+parent]]`]]
      
      $field = $modx->getOption('field',$scriptProperties,'pagetitle');
      
      $c = $modx->newQuery('modResource');
      $c->where(array('parent'=>$parent,'menuindex:>'=>$menuindex));
      $c->sortby('menuindex');
      $c->limit(1);
      
      $output = '';
      
      if ($object = $modx->getObject('modResource',$c)){
          $output = $object->get($field); 
      }
      
      return $output;
      


      called like that should give you the longtitle of the next resource in the same parent-container:

      [[getNext? &field=`longtitle` &menueindex=`[[+menuindex]]` &parent=`[[+parent]]`]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36604
        • 268 Posts
        hum..Thanks a lot!
        it's almost this, But I should have to give it only the current id of a page to find the id of its next (or prev) .

        So I tried to change your code into this..and of course I get a blank page when called.

        <?php
        //[[getNext? &field=`id`
         &menueindex=`[[+menuindex]]` &parent=`[[+parent]]`]]
        
        $field = $modx->getOption('field',$scriptProperties,'pagetitle');
        
        $c = $modx->newQuery('modResource');
        $c->where(array('parent'=>$parent,'menuindex:>'=>$menuindex));
        $c->sortby('menuindex');
        $c->limit(1);
        
        $output = '';
        
        if ($object = $modx->getObject('modResource',$c)){
            $output = $object->get($field); 
        }
        
        return $output;
          • 4172
          • 5,888 Posts
          you don't need to change the snippet - code.

          Try to call it like that:

          [[getNext? &field=`id` &menueindex=`[[+menuindex]]` &parent=`[[+parent]]`]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 36604
            • 268 Posts
            Quote from: Bruno17 at Oct 14, 2014, 04:04 AM
            you don't need to change the snippet - code.

            Try to call it like that:

            [[getNext? &field=`id` &menueindex=`[[+menuindex]]` &parent=`[[+parent]]`]]

            Yes but there was some typo 'menueindex' -> menuindex
            however blank page

            it's alaways called inside the PDO Resource tpl

            where I have the current id inside [[!+id]]

            [[!+id]]- <a class="down-arrow-btn" href="[[!getNext? &field=`[[!+id]]` &menuindex=`[[!+menuindex]]` &parent=`[[!+parent]]`]]"><i class="glyphicon glyphicon-chevron-down"></i> </a>


            Even if I test with hardcoded value (id 9 and menuindex 10 for examples, no way..blank page..

            Once the snippet code coorected from some typo. no more blank page BUT no output from the snippet it returns nothing [ed. note: elz064 last edited this post 12 years ago.]
              • 4172
              • 5,888 Posts
              with this in your code

              <?php
              //[[getNext? &field=`id`
               &menueindex=`[[+menuindex]]` &parent=`[[+parent]]`]]
              


              you will get a blank page, of course!
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 36604
                • 268 Posts
                yes I already corrected it in my previous answer.


                Quote from: Bruno17 at Oct 14, 2014, 04:49 AM
                with this in your code

                <!--?php
                //[[getNext? &field=`id`
                 &menueindex=`[[+menuindex]]` &parent=`[[+parent]]`]]
                


                you will get a blank page, of course!-->
                  • 36604
                  • 268 Posts
                  in fact, I'm trying to modify the pdoNeighbors to make it output 2 nex PL.
                  But I'm really not PHP friendly and I just can't understand the array mess this snippet deals with:

                  After line 65 it displays in the log all the wanted ids I'd like to become place holders
                  $pdoFetch->addTime('Found ids of neighbors: ' . implode(',', $ids));


                  I'm pretty sure is a piece of cake to genate +prev_id and +next_id from this start ..?

                    • 36604
                    • 268 Posts
                    I found a solution but this don't works if used in the template &tplNext (or &tplPrev).

                    Into the pdoResource tpl pdoNeighbors is called and

                    inside this tpl :
                    [[!pdoNeighbors? &id=`[[!+id]]` &tplWrapper=`PDON-tpl` &tplNext=`@INLINE ` &showLog=`0`]]
                    


                    and
                    $PDON-tpl:
                    <p class="text-center la_suite pdon[[!+id]]">
                    <a class="down-arrow-btn" href="#[[!pdoField?
                        &id=`[[!+neighbor_next_id]]`
                        &field=`pagetitle`
                    ]]"><i class="glyphicon glyphicon-chevron-down"></i> </a>
                    </p>


                    here's where I hacked the pdoNeihbors snippet :

                    $ids = array_merge($prev, $next, array($resource->parent));
                    
                            for($i=0;$i<count($next); $i++) { 
                    		//elz  ajout d'un placeholder contenant l'id de la page next. Ce PL n'est vu que dans le &tplWrapper (?)
                    		$neighbor_next_id = $next[$i];
                            //echo "(l'élément next[$i] est  $neighbor_next_id )"; 
                    		$modx->setPlaceholder('neighbor_next_id', $neighbor_next_id);
                    		//
                            } 
                    $pdoFetch->addTime('Found ids of neighbors: ' . implode(',', $ids));