Thursday 9 June 2016

Plugin release: Tag or Category term

We are glad to announce our first plugin called Tag or Category term_group Order.The purpose of this plugin is to group tags or categories from the WordPress dashboard. This allows queries that fetch terms to use ‘term_group’ as a sort order and and display them in a semantic way in archives and individual posts.
For example,
If we have three groups of categories for size, color and object, then categories displayed as
Small, Green, Table
Big, Blue, Chair
are more readable than
Table, small, green
Chair, big, blue



How to use  this plugin?
2. Visit WordPress Dashboard -> Posts – > Categories. You will find an additional field called ‘group’ to add the group number.
3. Add this code where you need to display the categories by group order.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$args array('orderby' => 'term_group''order' => 'ASC''fields' => 'all');
$terms = wp_get_object_terms($post->ID, 'category'$args );
$count count($terms);
if($count > 0){
echo 'Posted in <ul id="catlist">';
foreach ($terms as $term) {
echo '<li><a href="'.get_term_link($term->slug, 'category').'">'.$term->name.'</a> .</li>';
}
echo '</ul>';
}
4. You can group and display tags in a similar way. Just use the word ‘tag’ instead of ‘category’ in the code above.
We made this by modifying the Term menu order plugin by James Lafferty. Thanks, James.
Hope you find this useful. Please do share your comments and rate the plugin.

No comments:

Post a Comment