Latest Posts by Author
get the first attachment as a thumbnail (4 posts)

  1. Alessandro Cardinali
    Posted 4 years ago #

    I need to display the first image of the attachement's post.

    I always have 3 or + image in the gallery the plughin display the last attachment of my image gallery.

    I use this code:

    function latest_posts_by_author($array) {
       extract(shortcode_atts(array('author' => 'admin', 'show' => 3, 'excerpt' => 'false'), $array));
    	$args = array(
    		'post_parent' => $post->ID,
    		'author_name' => $author,
    		'posts_per_page' => $show
    	/* Gets posts form database */
    	$author_query = new WP_Query( $args );
    	$image = get_post_meta($post->ID, 'thumbnail', true);
    	/* Displays posts if available */
    	if( $author_query ) {
    		$html = '<ul class="thumbnails">';
    		while ( $author_query->have_posts() ) : $author_query->the_post();
    			$html .= '<li class="related_author_post_thumb">';
    			if ($image == 0) {
    			$html .= '<a class="thumbnail" href="' . get_permalink() . '" title="' . get_the_title() . '" alt="' . get_the_title() . '">'. get_the_post_thumbnail($numpost->ID, 'thumbnail').'</a>';
    			$html .= '</li>';
    			$html .= '</ul>';
    			$html .= '<div class="clearboth"></div>';
    	/* Resets Post Data */
       return $html;
    add_shortcode('latestbyauthor', 'latest_posts_by_author');

    can some body help me?


  2. Alex Mansfield
    Plugin Author

    Posted 4 years ago #

    The newest version of the plugin (0.8.1) has code included to display the post thumbnail. However, it is commented out because I couldn't guarentee that it would display properly with every theme, due to varying text sizes, line-heights, etc. However, feel free to uncomment those sections and play around. I've also updated the inline documentation so you should be able to figure out what's going on pretty easily. Let me know if you have any other questions.

  3. Shonu
    Posted 4 years ago #

    Why commenting out ? just check for a shortcode parameter. If not there, then DON'T do, if there and set properly, then do. Up to the user to "risk" it.

  4. Alex Mansfield
    Plugin Author

    Posted 4 years ago #

    Right now it is still up to the user to "risk" it. The extra step ensures that people understand the risk they're taking, rather than just adding a shortcode parameter and wondering why there are problems. If it were guaranteed that everyone would read the documentation before using a plugin, then maybe I would feel more free to add experimental features. I would rather someone request a feature than have actual problems with the plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Latest Posts by Author
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic