WordPress.org

Ready to get started?Download WordPress

Forums

"Featured" Section using multiple "get_posts" queries (3 posts)

  1. KeenanPayne
    Member
    Posted 1 year ago #

    Hello all,

    So I own and designed the site Default Prime (http://defaultprime.com). I am coding the featured posts section at the top, and am having quite a bit of trouble. Here's the code that I am using:

    <ul>
    	<li>
    	<div class="featuredleft"> <!--Show-->
    		<?php
    			$args = array( 'numberposts' => 1, 'category' => 4809, );
    			$lastposts = get_posts( $args );
    				foreach($lastposts as $post) : setup_postdata($post); ?>
    		<?php if ( has_post_thumbnail() ) {
    			the_post_thumbnail( 'featuredleft' );
    		} ?>
    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<?php echo my_excerpt(30); ?>
    		<?php endforeach; ?>
    	</div>
    	</li>
    	<li>
    	<div class="featuredlast"><!--Podcast-->
    		<?php
    			$args = array( 'numberposts' => 1, 'category' => 2, );
    			$lastposts = get_posts( $args );
    				foreach($lastposts as $post) : setup_postdata($post); ?>
    		<?php if ( has_post_thumbnail() ) {
    			the_post_thumbnail( 'featuredmiddle' );
    		} ?>
    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<?php echo my_excerpt(20); ?>
    		<?php endforeach; ?>
    	</div>
    	</li>
    	<li>
    	<div class="featuredmiddle"><!--Review-->
    		<?php
    			$args = array( 'numberposts' => 1, 'category' => 3, );
    			$lastposts = get_posts( $args );
    				foreach($lastposts as $post) : setup_postdata($post); ?>
    		<?php if ( has_post_thumbnail() ) {
    			the_post_thumbnail( 'featuredmiddle' );
    		} ?>
    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<?php echo my_excerpt(20); ?>
    		<?php endforeach; ?>
    	</div>
    	</li>
    	<li>
    	<div class="featuredmiddle"><!--Column-->
    		<?php
    			$args = array( 'numberposts' => 1, 'category' => 4743, );
    			$lastposts = get_posts( $args );
    				foreach($lastposts as $post) : setup_postdata($post); ?>
    		<?php if ( has_post_thumbnail() ) {
    			the_post_thumbnail( 'featuredmiddle' );
    		} ?>
    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<?php echo my_excerpt(20); ?>
    		<?php endforeach; ?>
    	</div>
    	</li>
    	<li>
    	<div class="featuredmiddle"><!--Editorial-->
    		<?php
    			$args = array( 'numberposts' => 1, 'category' => 5768, );
    			$lastposts = get_posts( $args );
    				foreach($lastposts as $post) : setup_postdata($post); ?>
    		<?php if ( has_post_thumbnail() ) {
    			the_post_thumbnail( 'featuredmiddle' );
    		} ?>
    		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<?php echo my_excerpt(20); ?>
    		<?php endforeach; ?>
    	</div>
    	</li>
    	</ul>

    The problem is, even though I have five instances of the "get_post" query to display the categories that I want, only four of them are showing up (screenshot here: http://i.imgur.com/Hpe0I.png).

    Could anybody just take a quick look over my code and see if I have any errors? I have been working for hours and cannot find anywhere that I have made a mistake and would love to get this fixed soon.

    Thanks everybody!
    -Keenan

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    'featuredlast' = cat 2 does not seem to have any posts.

  3. KeenanPayne
    Member
    Posted 1 year ago #

    Wow, I can't believe I overlooked that. I guess I just didn't even think it could be that.

    Thank you very much for helping me with that, I really appreciate it.

Topic Closed

This topic has been closed to new replies.

About this Topic