Last active
December 17, 2015 14:39
-
-
Save tkc49/5625795 to your computer and use it in GitHub Desktop.
記事毎に所属しているカスタム分類を表示した場合、カスタム分類の一覧表示の並び順と一緒の並びにする
※別途カスタム分類の並び順を制御するプラグインが必要
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// functions.php に追記 | |
function terms($a, $b){ | |
if ( intval($a->term_order) == intval($b->term_order)) { | |
return 0; | |
} | |
return (intval($a->term_order) < intval($b->term_order)) ? -1 : 1; | |
} | |
function terms_sort($terms, $object_ids, $taxonomies, $args){ | |
if(!is_admin()){ | |
usort($terms , "terms"); | |
} | |
return $terms; | |
} | |
add_filter('wp_get_object_terms','terms_sort',99,4); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 出力させたい箇所に記載 --> | |
<ul> | |
<?php $lists = wp_get_post_terms($post->ID,'タクソノミー名',array( 'orderby'=>'order', 'order'=>'ASC' ) ); ?> | |
<?php foreach($lists as $list): ?> | |
<li><a href="<?php echo esc_url(get_term_link($list,'タクソノミー名')); ?>" title="<?php echo esc_attr($list->name); ?>"><?php echo esc_html($list->name); ?></a></li> | |
<?php endforeach; ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment