WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] Display Tags With List (3 posts)

  1. SmashedUpSanity
    Member
    Posted 1 year ago #

    Is there anyway to include the posts tags within the ol of a category post list item?

    So each ol item would have the post title, the date then the tags for that post?

    Thanks.

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. Bill Erickson
    Member
    Plugin Author

    Posted 1 year ago #

    Yes it is. You'll need to write an output filter to change what information is output. Here's an example: http://www.billerickson.net/code/display-posts-shortcode-full-content/

    (The example changes the excerpt to full post content which isn't what you're looking for, but it does show you how to use the output filter).

  3. makbeta
    Member
    Posted 1 year ago #

    I came across this article, but didn't find the link helpful. I've used other snippets to construct the function below, which will display tags if include_tags='true' is specified in the shortcode itself.

    add_filter( 'display_posts_shortcode_output', 'display_posts_with_tags', 10, 7 );
    function display_posts_with_tags( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
    	$tags = '';
    		if (array_key_exists('include_tags', $atts) && $atts['include_tags'] ) {
    			$posttags = get_the_tags();
    			if ($posttags) {
    				$tags = '<div class="tags">';
    			  foreach($posttags as $tag) {
    			    $tags .= $tag->name . ' ';
    			  }
    			  $tags .= '</div>';
    			}
    		}
    
    	// First check if an excerpt is included by looking at the shortcode $atts
    	if ( $atts['include_excerpt'] )
    		// Now let's rebuild the excerpt with the facebook code at the end
    		$excerpt = '<div class="excerpt">' . get_the_excerpt() . '</div>';
    	else $excerpt = '';
    
    	// Now let's rebuild the output. Only the excerpt changed so we're using the original $image, $title, and $date
    	$output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $excerpt . $tags . '</' . $inner_wrapper . '>';
    
    	// Finally we'll return the modified output
    	return $output;
    }

    Hope this helps someone.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.