Display first post of each category type (WordPress)
<p>I'm new to WordPress and trying to work in a bit of custom code into a portion of the home page that is meant to display the #1 trending post of each of three categories (white papers, article, and post). The code as is is just displaying (from what I can tell) the 3 most recent posts regardless of the category type:</p>

<p>

<pre><code>$args = array('posts_per_page' =&gt; 3);
$loop2 = new WP_Query($args);
while ($loop2-&gt;have_posts()) : $loop2-&gt;the_post();
    $thumbnail = get_post_thumbnail_id(); $imageurl = wp_get_attachment_image_src($thumbnail,'theme-360x240');
    $class="";  $categories = get_the_category();
    if($categories[0]-&gt;slug == 'articles'){
        $class="article-icon";
    } else if($categories[0]-&gt;slug == 'videos' || $categories[0]-&gt;slug == 'webinars'){
        $class="video-icon";
    } else if($categories[0]-&gt;slug == 'white-papers' || $catgories[0]-&gt;slug == 'case-studies' || $categories[0]-&gt;slug == 'industry-information' || $categories[0]-&gt;slug == 'posts') {
        $class="whitepapers-icon";
    } else {
        $class="event-icon";
    }
    $posttype = get_post_type(get_the_ID()); ?&gt;
    &lt;div class="card radius shadowDepth1"&gt;
        &lt;div class="card__image border-tlr-radius"&gt;

            &lt;img src="&lt;?php if(!empty($imageurl[0])) { echo $imageurl[0]; } else { echo 'http://placehold.it/360x205'; } ?&gt;" alt="image" class="border-tlr-radius"&gt;
        &lt;/div&gt;

        &lt;div class="card__content card__padding"&gt;
            &lt;div class="card__share"&gt; &lt;?php $iconurl = z_taxonomy_image_url($categories[0]-&gt;term_id); ?&gt;
                &lt;a &lt;?php if($iconurl) { ?&gt;style="background:url(&lt;?php echo $iconurl; ?&gt;);"&lt;?php } ?&gt; id="share" class="share-toggle share-icon &lt;?php echo $class; ?&gt;" href="&lt;?php echo get_category_link($category[0]-&gt;term_id); ?&gt;"&gt;&lt;/a&gt;
            &lt;/div&gt;

            &lt;div class="card__meta"&gt;
                &lt;?php if($posttype == 'tribe_events') { ?&gt;
                    &lt;a href="&lt;?php echo home_url(); ?&gt;/events"&gt;Events&lt;/a&gt;
                &lt;?php } else { ?&gt;
                    &lt;a href="&lt;?php echo get_category_link($categories[0]-&gt;term_id); ?&gt;"&gt;&lt;?php echo $categories[0]-&gt;name; ?&gt;&lt;/a&gt;
                &lt;?php } ?&gt;
            &lt;/div&gt;

            &lt;article class="card__article"&gt;
                &lt;h2&gt;&lt;a class="show_pop" href="&lt;?php echo get_permalink(); ?&gt;"&gt;&lt;?php echo get_the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;

                &lt;p&gt;&lt;?php $content = get_the_content(); echo wp_trim_words($content,'15','...'); ?&gt;&lt;/p&gt;
                &lt;a class="show_pop read-more" href="&lt;?php echo get_permalink(); ?&gt;"&gt;Read More&lt;/a&gt;
            &lt;/article&gt;
        &lt;/div&gt;
    &lt;/div&gt;
</code></pre>

<p>

<p>None of this code was created by me, so I can't say how well-done it is or how reliable it is...but that is what's there. </p>

<p>I apologize if this is a dumb question--I've just never done much in WordPress! Any help would be appreciated.</p>