wordpress – change the order of tags from the_tags()

I’m currently getting the list of tags like this:

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

Which displays them alphabetically. I need to change the order though. I only have 4 possible tags and I know the order they should go in, but it’s not alphabetical.

Read More

EDIT: I posted the wrong code. This is how the tags are getting displayed:

<?php wp_tag_cloud('smallest=9&largest=9&format=flat' );?>

I need to display that in custom order ‘a’, ‘b’, ‘c’, ‘d’

Related posts

Leave a Reply

2 comments

  1. I believe you should be able to get the tags first like this and then do something with them:

    $posttags = get_the_tags();
    if ($posttags) {
      $arr = array();
      $possible_tags = array('a', 'b', 'c', 'd');
      foreach ($possible_tags as $possible) {
        if (array_search($possible, $posttags) !== FALSE) {
          array_push($arr, $possible);
        }
      }
      echo '<ul><li>'. implode('</li><li>', $arr) . '</li></ul>';
    }
    

    Docs at http://codex.wordpress.org/Function_Reference/get_the_tags

  2. This would require editing the the_tags function. I think they’re currently ordered by their ID. You could possibly rejig the IDs (deleting, re-adding) to change the order. This would avoid extra code.