How to create a tag list index?
-
I want to create a page that lists all tags but only if the post has been published. Cause right now its showing tags from scheduled posts as well which I don’t want. Can someone help me fix this code?
<?php /* Template Name: Tags List */ /* Process ================================================= */ $list = ''; $tags = get_terms( 'post_tag' ); $groups = array(); if( $tags && is_array( $tags ) ) { foreach( $tags as $tag ) { $first_letter = strtoupper( $tag->name[0] ); $groups[ $first_letter ][] = $tag; } if( !empty( $groups ) ) { foreach( $groups as $letter => $tags ) { $list .= "\n\t" . '<h2>' . apply_filters( 'the_title', $letter ) . '</h2>'; $list .= "\n\t" . '<ul>'; foreach( $tags as $tag ) { $url = attribute_escape( get_tag_link( $tag->term_id ) ); $count = intval( $tag->count ); $name = apply_filters( 'the_title', $tag->name ); $list .= "\n\t\t" . '<li><a href="' . $url . '">' . $name . '</a> (' . $count . ')</li>'; } $list .= "\n\t" . '</ul>'; } } }else $list .= "\n\t" . '<p>Sorry, but no tags were found</p>'; /* OUTPUT ============================= */ get_header(); ?> <div id="content"> <div id="content-list"> <h1>Tag List</h1> <?php print $list; ?> </div> </div> <?php get_footer(); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to create a tag list index?’ is closed to new replies.