How to generate a list of field items using the field item name programmatically in Drupal 7? I need a way to generate a simple list of all the items in a particular field. The field name is field_portfolio_description, and I'm looking to simply loop through the results and output each item into an unordered list. For example: 

&lt;ul&gt;
  &lt;li&gt;Item 1&lt;/li&gt;
  &lt;li&gt;Item 2&lt;/li&gt;
  &lt;li&gt;Item 3&lt;/li&gt;
&lt;/ul&gt;


Is there a way to do this programmatically without using a module like Views? I would also like to display the data in page.tpl.php not node.tpl.php. I tried checking out some Drupal functions like field_info_field but they weren't much help. 

Update: 

I've been working with the following function in my template.php file:

function blocks_preprocess_node(&amp;$vars) {
  $node = $vars['node'];
  if ($node-&gt;type == 'portfolio') {
    $vars['description'] = $node-&gt;field_portfolio_description[LANGUAGE_NONE][0]['value'];
  }
}


However a quick var_dump($description) where I'm trying to access the data brings up null. Am I on the right track? 

edit: fixed typo
You're pretty much on the right track. Try something like:

function blocks_preprocess_node(&amp;$vars) {
  $node = $vars['node'];
  if ($node-&gt;type == 'portfolio') {
    $portfolios = field_get_items('node', $node, 'field_portfolio_description');
    $items = array();
    foreach ($portfolios as $folio) {
      $items['data'] = $folio['value'];
    }
    $vars['description'] = theme('item_list', array('items' =&gt; $items));
  }
}


Adding stuff to nodes like this is maybe better in hook_node_view() in a custom Module. Because you're altering the node's content before its shown (and its adding derived content to the node, not just changing some markup at the theme layer).

Code is untested and just Help. (but should mostly work)

Resources


theme_item_list function docs
field_get_items function docs
alternatively create a "Code Field" using Display suite to encapsulate this custom code field to a view_mode (aka, magic). See this tutorial on youtube on DS and custom fields.