How can I output aliases in a print function, so I can render links using aliases instead of nid?
You should use the l() function:


  Formats an internal or external URL link as an HTML anchor tag.
  
  This function correctly handles aliased paths and adds an 'active'
  class attribute to links that point to the current page (for theming),
  so all internal links output by modules should be generated by this
  function if possible.


So:

&lt;?php print l('Link text', 
              'node/' . $row-&gt;nid, 
               array(
                 'attributes' =&gt; array(
                   'class' =&gt; array(
                     'w-inline-block',
                     'portfolio-photo',
                     'portfolio-1')))); ?&gt;


You have to supply classes and any other attributes to the l() function.

Note that the first l() parameter (the 'Link text') can be HTML. For this you have to pass in the options array an element HTML set to TRUE. The above example can be:

&lt;?php print l('&lt;img src="/someimg"&gt;Some text&lt;/img&gt;', 
              'node/' . $row-&gt;nid, 
               array(
                 'attributes' =&gt; array(
                   'class' =&gt; array(
                     'w-inline-block',
                     'portfolio-photo',
                     'portfolio-1')
                   )
                 'html' =&gt; TRUE,
                 )
             ); ?&gt;


Also, as noted by the documentation fragmento above, the l() functions handles the aliases. This is because internally drupal_get_path_alias() function is used.