0

I have the following function that returns the tags of the current post:

<?php the_tags( '<ul> <li>', '</ li> <li>', '</ li> </ ul>' ); ?>

Example:

enter image description here

Is there any way to split the result into 2 columns?

Would return something like this:

enter image description here

Any hint is welcome. Thank you friends!

1
  • 1
    you can also check out the multi columns in CSS3, but that might not cover all browsers ;-)
    – birgire
    Commented May 7, 2013 at 17:47

1 Answer 1

2

Use get_the_tags instead of the_tags to grab an array of tags, and array_chunk to split it. You will then need to build a loop to display the tags.

$tags = get_the_tags(); 
if (!empty($tags)) {
  $tags = array_chunk($tags,ceil(count($tags)/2),true);
  foreach($tags as $v) {
    echo '<ul>';
    foreach ($v as $tag) {
      echo '<li><a href="'.get_tag_link($tag->term_id).'">' . $tag->name . '</a></li>'; 
    }
    echo '</ul>';
  }
}

Reference

http://codex.wordpress.org/Function_Reference/get_tag_link

4
  • Perfect @s_ha_dum! Now we need to find a way to use CSS3 to position the first <ul> left.
    – BobGCA2
    Commented May 7, 2013 at 18:25
  • All you should need to do is float the <ul>s.
    – s_ha_dum
    Commented May 7, 2013 at 18:27
  • Oops, that's what I meant, lol.
    – BobGCA2
    Commented May 7, 2013 at 18:30
  • I thought I should just add float in a <ul>. But really worked (at least in Chrome).
    – BobGCA2
    Commented May 7, 2013 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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