We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36620
    • 65 Posts
    I have a simple snippet that lists resources as an unordered list:

     $sql ="SELECT id, longtitle, alias FROM `modx_site_content`;";
        $result = mysql_query($sql);
            while ($row = mysql_fetch_assoc($result)) {                  
    	  $output .= '<li><a href="index?q=' . $row['id'] . '">' . $row['longtitle'] . '</a></li>';   
                              }


    The resultant link(s) work fine mysite.com/index?q=12 but I was hoping it would automatically be parsed as a Friendly URL's to match the rest of the site. If I'm just listing the resources in just one folder I can use the 'alias' and hand-code the directory but that doesn't work for more than one folder.

    Is there a way of automatically converting the output to the 'Friendly URL' equivalent within the snippet? [ed. note: randall last edited this post 15 years, 2 months ago.]
      • 4041
      • 788 Posts
      Give this a try:
      $output .= '<li><a href="' . $modx->makeURL($row['id'] ). '">' . $row['longtitle'] . '</a></li>';
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 33968
        • 863 Posts
        Yes, you can use:
        $url = $modx->makeUrl($row['id']);
        

        The output will be a Friendly URL if they are enabled in your system settings.
          • 36620
          • 65 Posts
          Thanks breezer and Lucas, works great!