Support » Fixing WordPress » get_posts padding to equal posts_per_page

  • I’m running a get_posts() using a variable for the item count to display up to 5 items on one page and up to 7 items on another page.

    However if I only have three posts, instead of only having three in the post array I have either 5 or 7. Some of the elements in the extra results seem to have the same values as the first post in the array, while other elements seem to be empty.

    Any ideas what I’m doing wrong here?

    <?php$news_posts = get_posts ( array ( 'posts_per_page' => $item_count, 'category_name' => 'news' ) );>
    <div id="quicklinks-1" class="ql">
          			<?php foreach ( $news_posts as $newspost ) : ?>
          				<p class="quicklink-item">
          					<a href="<?php echo get_permalink( $newspost->ID ); ?>">
          							if ( has_post_thumbnail( $newspost->ID ) ) :
          								echo get_the_post_thumbnail( $newspost->ID, 'quick-links' );
    								else : ?>
    									<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/icn-news.jpg" width="37px" height="37px" alt="<?php echo $newspost->post_title; ?>" />
    						<span class="headline">
    							<a href="<?php echo get_permalink( $newspost->ID ); ?>">
    								<?php echo get_post_meta( $newspost->ID, 'quick-link-title', true ); ?>
    								<?php //echo $newspost->post_title; ?>
    						<span class="date">
    							<?php echo get_the_time('d M, Y', $newspost->ID); ?>
    					<?php endforeach; ?>
          			<div class="clear"></div>
          			<div class="more">
          			<a href="<?php echo home_url ( '/category/news/' ); ?>">
                 		<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/more.jpg" />
          		</div><!-- #quicklinks1 -->
  • The topic ‘get_posts padding to equal posts_per_page’ is closed to new replies.