Get News Tags
-
Hi,
I am trying to grab the News Tags and list them in my News Archive
This is what i got in my function simple_news_loop_custom() in my Themes functions.php:
// Get Tags $args = array( 'orderby' => 'name', 'order' => 'ASC' ); $tags = get_tags($args); $html = '<span id="news-pill" class="badge badge-pill badge-secondary"><i class="fas fa-tag"></i> '; foreach ( $tags as $tag ) { $tag_link = esc_url( get_tag_link( $tag->term_id ) ); $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>"; $html .= "{$tag->name}</a>"; } $html .= '</span>'; if ( !empty($tags) ) : echo $html; else : echo 'no tags'; endif;
I built in the Troubleshoot “no tags” and that is what i get for all my NewsPosts (Yes, I did create the Tags in the Admin area.
————–
For Categories I used (and it works fine):
// Get Categories $categories = get_categories( array( 'orderby' => 'name', 'order' => 'ASC' ) ); foreach( $categories as $category ) { $category_link = sprintf( '<span id="news-pill" class="badge badge-pill badge-secondary"><i class="fas fa-folder"></i> <a href="%1$s" alt="%2$s">%3$s</a></span>', esc_url( get_category_link( $category->term_id ) ), esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ), esc_html( $category->name ) ); echo $category_link; }
Can you please enlighten me on how to to this? ??
Cheers
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Get News Tags’ is closed to new replies.