I want to display taxonomies instead of categories on the homepage of my blog. What can I do to achieve this?
3 Answers
I think what you are looking for is this: http://codex.wordpress.org/Function_Reference/get_terms
Example of how to get all my_taxonomy
terms and echo them in an unordered list.
$terms = get_terms( "my_taxonomy" );
$count = count( $terms );
if ( $count > 0 ){
echo "<ul>";
foreach ( $terms as $term ) {
echo "<li>$term->name</li>";
}
echo "</ul>";
}
-
i dont want to display taxonomy in list format. i want to display in the form of post.– nehaJan 17, 2012 at 10:55
-
@neha Well, you can use the
$terms
variable for anything, I was just giving you an example of how to grab all of the terms from a custom taxonomy and do something with them. :) I don't know exactly what you are trying to do with the terms so that is as specific as anyone can get.– JaredJan 17, 2012 at 11:35 -
i exactly want to display post by term of taxonomy instead of categories. will u guide me if u know the exact code .if u know then please tell me also in which exact file i replace your code.– nehaJan 18, 2012 at 5:49
-
@neha The problem is I don't know exactly what you are trying to do, so I wouldn't know where you need to put the code. I suggest if you don't know much about PHP and WordPress to not go about trying to code things yourself. If you insist on coding it yourself anyways without prior PHP knowledge, you are going to have to play around with the code I posted above until it works how you want it, as it is the function you are looking for.– JaredJan 18, 2012 at 8:18
-
i know PHP and wordpress but problem is that i want the suitable code for my query.actually my boss doesnt want the taxonomy in list format . i used this code already thats y i want new code to fulfill boss requirement.– nehaJan 18, 2012 at 9:04
@neha
In the code posted by Jared,
please look at this line --> echo "<li>$term->name</li>
That's what made the output into a list.
For anyone to suggest the code, you should've mentioned how would you like to have it output?
Say, for a big title --> echo "<h1>$term->name</h1>
Or, into a blockquote --> echo "<blockquote>$term->name</blockquote>
Or, as a regular paragraph --> echo "<p>$term->name</p>
How exactly would you like it to be displayed?
Try
wp_list_categories('taxonomy=operating_system');
-
what's this what do u want to say?? In which file i replace this code?? i want to display post in terms of taxonomy instead of categories.– nehaJan 18, 2012 at 5:50