Custom Fields
Re-Envisioned
Support MB Custom Taxonomy Taxonomy description in loop (and limit description length)

  • Creator
    Topic
  • #29304
    Resolved Heave
    Participant

    O each taxnomy has a description.
    On a page i would like to display a look with all taxonomy with and excerpt of the description.

    So far i came up with

    
    
        <?php
            $terms = get_terms(
            array(
            'taxonomy'   => 'marque',
            'hide_empty' => false
    ,       )
            );
    
        ?>
    <div class="h-grid-marque">
        
            <?php
    
                // Getting images
                foreach ( $terms as $term ) {
                    //$term_id = get_queried_object_id();
    
                    $value = rwmb_meta( 'poptxt', ['object_type' => 'term'], $term->term_id );
                    echo $value;
                    
    
                    $image_ids = get_term_meta( $term->term_id, 'h-category-featured-image', false ); // Media fields are always multiple.
                    //var_dump($image_ids);
                    foreach ( $image_ids as $image_id ) {
                        $image = RWMB_Image_Field::file_info( $image_id, array( 'size' => 'marque-gallery' ) ); 
                ?>
    
                        
                <div class="grid-element c-shadow"> 
                            <a class="pop-link" href='<?php echo get_term_link( $term )?>'>
                            <img class="h-img-marque" src=" <?php echo $image['url'] ?>">
                                
                                <div class="c-padding-xs"><h3><?php echo $term->name ?></h3>
                                    <p><?php echo wp_trim_words( get_the_excerpt(), 20, '...' ); ?></p>
                                    <p><?php echo $term->description ?></p></div>
                                </a>
                 </div>
                        
    
                        <?php
                        }   
                    }
                ?>
    </div>

    Problem, <p><?php echo wp_trim_words( get_the_excerpt(), 20, '...' ); ?></p> display the excerpt of the current page and not the excerpt of the description listed.

    How can i achieve that ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #29310
    Heave
    Participant

    Update → <p><?php echo wp_trim_words( term_description($term), 20, '...' ); ?></p>

    #29319
    Long Nguyen
    Moderator

    Hi,

    Thanks for share, term_description() is the right function to get a term description.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.