3

For example, if I'm building a list in a plugin that loops over an array to produce a list ul or ol. I typically see code as follows.

foreach($list as $item) {
  $output .= '<li>' . $item['value'] . '</li>';
}

I guess I'm looking to see if there is a comparable to such functions in the Drupal world such as theme_list() (reference). I'm looking to give my list of items to a function and have it write the HTML block in a standardized way.

3

There are specific functions like wp_list_categories() and wp_list_pages() along with some others which will do this for you but for arbitrary arrays, WordPress doesn't have a function to neatly print it out into HTML for you. You could simply write your own functions for this purpose if you really need to I guess.

2

For tree-like structures (e.g. nested lists) you can extend the Walker class: https://codex.wordpress.org/Class_Reference/Walker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.