We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17233
    • 15 Posts
    How can I get parent list of doc
    and then list it out in an array
    so I can loop the list out in colunms of choices


    How to make an array for print out ’menutitle’ huh????????


    $states= array( huh???);


    this is the code for list out in columns, $states change with ’ menutitle of parent ’


    //***********************************************************************
    // $states= array("Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
    // "Connecticut", "Delaware", "Dist of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois",
    //"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts",
    //"Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire",
    //"New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",
    //"Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee",
    //"Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming");

    //number of records
    $num_records = sizeof($states);

    //max number of columns
    $max_cols = 3;

    //find the number of records that should be in each column
    $records_per_col = ceil($num_records / $max_cols);
    print ’<strong>Displaying State Data in Columns</strong>

    ’;

    print ’<table border = "1" width = "100%">
    <tr>
    <td valign = "top">
    <table border = "0">
    <tr>’;

    //start a $count variable
    //its here to match up with the $records_per_col for comparison as seen below
    //in the loop
    $count = 0;
    foreach ($states as $state) {

    //check if the current count is greater than the $records_per_col
    if ($count >= $records_per_col) {
    print ’</tr></table></td><td valign = "top"><table border = "0"><tr>’;

    //set the count variable back to 0 or else there will be a ton of columns
    $count = 0;
    } else {
    //if not start a new row for the next piece of data
    print ’</tr><tr>’;
    }
    //print the data
    print ’<td>’.$state.’<td>’;

    //increment the $count variable
    $count++;
    }

    print ’</table>
    </td>
    </tr>
    </table>’;


    //***********************************************************************


    Many thanks
      • 7231
      • 4,205 Posts
      I dont undertand the question. You want to change this script to gather menutitle info rather than the states? What is the relationship between menutitle and the states?
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 17233
        • 15 Posts
        the $states is the array
        I do not want to use the states of america, I want to use the Child pages of one page on the website
        example I have a page ’Products’
        Under page of Products, I have 18 other pages, and I want to display them in the footer of the site

        col no 1 col no 2 col no 3
        -----------------------------------------------------------------------------------
        page 1 page 7 page 13
        page 2 page 8 page 14
        page 3 page 9 page 15
        page 4 page 10 page 16
        page 5 page 11 page 17
        page 6 page 12 page 18


        like this in 3 cols

        many thanks
          • 4172
          • 5,888 Posts
          this script will generate a table like this:

          col no 1 col no 2 col no 3
          -----------------------------------------------------------------------------------
          page 1 page 2 page 3
          page 4 page 5 page 6
          page 7 page 8 page 9
          page 10 page 11 page 12
          page 13 page 14 page 15
          page 16 page 17 page 18

          is that what you want?
          can also be done with ditto and a little bit phx
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 17233
            • 15 Posts
            ok, how do I do that, with ditto or a little bit ?
              • 4172
              • 5,888 Posts
              here is a tableless easy one example:

              <div style="width:450px">
              [!Ditto? &tpl=`menutitleCell` &parents=`23` &display=`all`!]
              </div>


              change parents to your parent

              chunk menutitleCell:
              <div style="width:150px;float:left;">
              [+pagetitle+]
              </div>
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 17233
                • 15 Posts
                Bruno17 this display a long list of childpages, i don’t it split in colunms

                thanks anyway
                  • 4172
                  • 5,888 Posts
                  you can also try this:

                  <?php
                  
                  //[!maketables!]
                  //[!maketables? &parent=`xx` &max_cols=`xx`!]
                  
                  $fields = 'id, pagetitle, description, alias, parent, menutitle';
                  $active = 1;
                  $deleted = '0';
                  $parent = isset ($parent)?$parent:$modx->documentObject['id'];
                  $max_cols = isset ($max_cols)?$max_cols:3;//max number of columns
                  
                  $docs = $modx->getDocumentChildren($parent, $active, $deleted, $fields, $where, $sort, $direction, $limit);
                  
                  $num_records = count($docs);
                  
                  
                  //find the number of records that should be in each column
                  $records_per_col = ceil($num_records/$max_cols);
                  
                  $output= '<table border = "1" width = "100%">
                        <tr>
                        <td valign = "top">
                        <table border = "0">
                        <tr>';
                  
                  //start a $count variable
                  //its here to match up with the $records_per_col for comparison as seen below
                  //in the loop
                  $count = 0;
                  foreach ($docs as $doc)
                  {
                  
                      //check if the current count is greater than the $records_per_col
                      if ($count >= $records_per_col)
                      {
                          $output.= '</tr></table></td><td valign = "top"><table border = "0"><tr>';
                  
                          //set the count variable back to 0 or else there will be a ton of columns
                          $count = 0;
                      } else
                      {
                          //if not start a new row for the next piece of data
                          $output.= '</tr><tr>';
                      }
                      //print the data
                      $output.= '<td>'.$doc['pagetitle'].'<td>';
                  
                      //increment the $count variable
                      $count++;
                  }
                  
                  $output.= '</table>
                        </td>
                        </tr>
                        </table>';
                  
                  return $output;	  
                  ?>
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 17233
                    • 15 Posts
                    Bruno17 you are good
                    it’s perfect
                    Many thanks to you
                      • 20648
                      • 26 Posts
                      Thank’s for this code.
                      One question:
                      What if I want to sort the ouput, not based on ID, but on pagetitle, publishdate etc.

                      eg.
                      &sort_cols=isset --> some code ?

                      In the snippetcall:
                      somthing like this:
                      [!maketables? &parent=`xx` &max_cols=`xx` &sort_cols=`pagetitle ASC`!]

                      How can I achieve this?