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

    Anyone know how to change the following code to use the menu item instead. So rather than change to the next ID (rubbish) it jumps to the next menu item in the tree? I don’t know the API for it and can’t find it anywhere.

    <?php
    $newId = $modx->documentIdentifier +1;
    $link = $modx->makeUrl($newId);
    return $link;
    ?>


    Thanks very muchly

    D
      • 6649
      • 25 Posts
      If it is useful, I have got this far, but I am getting a syntax error, unsurprisingly.

      <?php
      $mnuidx = $modx->db->getValue('SELECT MAX(menuindex)+1 as \'mnuidx\' FROM '.$modx->getFullTableName('site_content').'');
      if ($mnuidx<1) $mnuidx = 0;
      $newId = $modx->($munidx +1);
      $link = $modx->makeUrl($newId);
      return $link;
      ?>


      The problem resides in line 4, can anyone direct me?

      Cheers, D
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Your error is actually in line 3, the $modx->... needs to specify a function or a value, such as $modx->makeURL() or $modx->documentIdentifier.

        I don’t think this will do what you want in any case. You can’t make a URL from a menu index, it has to be from a document ID.

        Also, you need to consider that each branch of the document tree will have its own set of menu indexes, so for every section that has more than three documents you’ll have a menu index of 3.

        And you’ve got a typo, $munidx +1 should be $mnuidx +1

        Why don’t you just use the PrevJumpNext snippet? Or at least examine its code to see how it does it.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 6649
          • 25 Posts
          I am having so many flaming problems with this! >:(

          I have the PrevJumpNext snippet, created in a new snippet called PrevJumpNext. I then enter the following placeholders [+PJN_next+] and the [+PJN_prev+] into href tags on the template as I have previously made buttons to change documents. I know I am missing something, ubt I cannot for the life of me figure it out. Can someone please explain in DUMMY terms what on earth I am doing wrong?!?!

          Thanks a million

          Dave01
            • 6649
            • 25 Posts
            How am I doing here:

            <?php
            $prev = $current-1;
            $next = $current+1;
            
            $children = $etomite->getActiveChildren($parentid, $sortBy, $sortHow, $fields);
            
            $limit = count($children);
            
            // Prev item
            if($prev > 0 && $displayTitle==false){
            	$PJN_prevPlaceHolder = "<a href='[~".$my_array[$prev]['id']."~]'>".$prevText."</a>";
            } elseif($prev > 0 && $displayTitle==true) {
            	$PJN_prevPlaceHolder = "<a href='[~".$my_array[$prev]['id']."~]'>".$my_array[$prev]['pagetitle']."</a>";
            } elseif($prev <= 0 && $displayNoPrevNext == true) {
            	$PJN_prevPlaceHolder = $noPrevNextText;
            }
            
            // Next item
            if($next <= $limit && $displayTitle==false){
            	$PJN_nextPlaceHolder = "<a href='[~".$modx[$next]['id']."~]'>".$nextText."</a>";
            } elseif($next <= $limit && $displayTitle==true) {
            	$PJN_nextPlaceHolder ="<a href='[~".$modx[$next]['id']."~]'>".$my_array[$next]['pagetitle']."</a>";
            } elseif($next > $limit && $displayNoPrevNext == true) {
            	$PJN_nextPlaceHolder = $noPrevNextText;
            }
            
            if ($usePlaceHolder==false) {
            
            	// Here starts the output
            	$output = "";
            	$output .= "<div class='PJN_Menu'>";
            	
            	if($displayFixed==true) {
            		$output .= $PJN_firsPlaceHolder." < ";
            	} 
            	
            	$output .= $PJN_prevPlaceHolder." | ";
            	
            	if($useJump) {
            		$output .= $PJN_jumpPlaceHolder." | ";
            	} else {
            		$output .= $PJN_indexPlaceHolder." | ";
            	}
            		
            	$output .= $PJN_nextPlaceHolder;
            	
            	if($displayFixed==true) {
            		$output .= " > ".$PJN_lastPlaceHolder;
            	} 
            	
            	$output .= "</div>";
            	
            	return $output;
            }
            else {
            	
            	// Set PlaceHolder
            	$modx->setPlaceholder('PJN_first',"<span class='PJN_Menu'><span class='PJN_First'>".$PJN_firsPlaceHolder."</span></span>");
            	$modx->setPlaceholder('PJN_prev',"<span class='PJN_Menu'><span class='PJN_Prev'>".$PJN_prevPlaceHolder."</span></span>");	
            	$modx->setPlaceholder('PJN_jump',"<span class='PJN_Menu'><span class='PJN_Jump'>".$PJN_jumpPlaceHolder."</span></span>");
            	$modx->setPlaceholder('PJN_index',"<span class='PJN_Menu'><span class='PJN_Indext'>".$PJN_indexPlaceHolder."</span></span>");
            	$modx->setPlaceholder('PJN_next',"<span class='PJN_Menu'><span class='PJN_Next'>".$PJN_nextPlaceHolder."</span></span>");
            	$modx->setPlaceholder('PJN_last',"<span class='PJN_Menu'><span class='PJN_Last'>".$PJN_lastPlaceHolder."</span></span>");
            	
            }
            ?>


            And then I have put the place holders in the href tags in the template

            Its still not working if you haven’t guessed!

            D