WordPress.org

Ready to get started?Download WordPress

Forums

get_terms without displaynig taxonomy name (5 posts)

  1. deepbevel
    Member
    Posted 1 year ago #

    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').'">
    '.$term->name.'</a></li>';
    }
    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.

  2. deepbevel
    Member
    Posted 1 year ago #

    never mind, looks like the taxonomy name was beng called by other code..

  3. 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:

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

    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
  4. deepbevel
    Member
    Posted 1 year ago #

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

    this is what I have in my list

    Style
    Landscape
    Botanical
    Portrait

    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.

  5. deepbevel
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.