All posts by pk
T Time with the Electric Eels
Earthless Meets Heavy Blanket Meets Production Error Double Purple LP #storageproblem
So Long and Thanks for All the $1.35 Coffee
Pearls for Bitcoin
Ultimate Time-Tracking App
Crazy Little Thing Called Civic Responsibility
How to Make Non-Alphabetical, Sequential Post Tags in WordPress
One thing I didn’t think I’d write about on this blog is code, so here I am writing about code. I wanted WordPress to format my imported Tumblr posts’ tag order. It’s a humorous diversion for myself (and, one hopes, the reader as well).
Turns out, this is not as easy as it would seem. WordPress lists tags alphabetically by default. And I didn’t want to use a plugin for what WP should do naturally. Here’s what I came up with.
There may be better ways to do this—if so, tell me. Otherwise, add this to your functions.php file
$posttags = get_the_tags(); $tagsArray = array(); if ($posttags) { foreach ($posttags as $tag) { $tagsArray[] = $tag->term_id; } $tags = get_tags( array('orderby' => '', 'include' => $tagsArray, 'fields' => 'all' )); if ($tags) { echo '<span class="tags-links">'; foreach ( (array) $tags as $tag ) { $tag_link = get_tag_link( $tag->term_id ); echo "<a href=\"{$tag_link}\">{$tag->name}</a>"; } echo '</span>'; } } //end if posttags