• In the code below, i created link using tax terms. The result i was expecting is when i click on a link, i would like to be redirected to a page showing all the posts for the terms. But it don’t work!!

    Could you please help?
    Thank you

    $terms = get_terms( 'smartphones' );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    foreach ( $terms as $term ) {
    echo '<div class="col col1-4">
    <a href="' . get_term_link( $term->slug, 'smartphones' ) . '">
    <img src="' . get_stylesheet_directory_uri() . '/images/' . lcfirst($term->name) . '.png"></a></div>';
    }
    }
Viewing 1 replies (of 1 total)
  • You can take reference from the below codes & try it. It should work. If not please post it.

    $args = array( 'hide_empty' => 0 );
    
    $terms = get_terms( 'my_term', $args );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
        $count = count( $terms );
        $i = 0;
        $term_list = '<p class="my_term-archive">';
        foreach ( $terms as $term ) {
            $i++;
        	$term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a>';
        	if ( $count != $i ) {
                $term_list .= ' &middot; ';
            }
            else {
                $term_list .= '</p>';
            }
        }
        echo $term_list;
    }

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘display posts when clicking term link’ is closed to new replies.