Support » Fixing WordPress » get_terms without displaynig taxonomy name

  • I’ve been slicing and dicing this to no avail, just trying to remove the part which outputs the taxonomy name link, but I want to keep the terms.

    $terms = get_terms('styles');
    echo '<ul>';
    foreach ($terms as $term) {
        echo '<li>
    <a href="'.get_term_link($term->slug, 'styles').'">
    echo '</ul>';

    Aside from not actually knowing which part is getting the taxonomy link, the syntax is too advanced for me, don’t understand the “.” and having trouble closing the backticks.

    please straighten me out if you can.

Viewing 4 replies - 1 through 4 (of 4 total)
  • never mind, looks like the taxonomy name was beng called by other code..

    Chris Olbekson


    Level 12 Bug Squasher & Forum Moderator

    Your code should not display the taxonomy name it is displaying the term name as an anchor for the link to the term archive page.

    So lets say your taxonomy is styles and as terms you have red, blue, green. Your function will display an ordered list of links to the archive pages like this.

    You could also write this function:

    <?php $terms = get_terms('styles'); ?>
    <?php foreach ($terms as $term) {  ?>
        	<a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?></a>
    <?php } ?>

    You can change the part that displays the anchor link by replacing <?php echo $term->name; ?> with whatever you want.
    Here are your options

    $term->term_id  //The ID assigned to the term
    $term->name  //The terms name ie: red, blue, green
    $term->slug  //The slug which will be lowercase with spaces replaced by a -
    $term->taxonomy  //The taxonomy ie: styles
    $term->description //The description if entered

    wow, thanks, I’ll have to dwell on that.

    this is what I have in my list


    I thought “Style” was the taxonomy name, which it is. But it’s also one of my terms, except plural “Styles”..

    So the “Style” link I get is indeed a term, not the taxonomy name, like I thought.

    Sorry, it’s an old project revisted and I forgot what I did..

    still your info is useful, I need to learn more about listing terms from custom taxonomies.

    new related questions:
    how might I exclude 1 term from the list?
    how might I specify the terms order in the list?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_terms without displaynig taxonomy name’ is closed to new replies.