0

Here i am trying to display top 6 post recent added post.But the problem is that first top post not displaying code is displaying top 6 post from top 2nd post except the top 1st post.

Bellow is sample which i have used to display sticky and post.

<ul>
<?php
**//To display sticky on top** 
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$sticky= get_option( 'sticky_posts' );

$args = array(
    'cat' =>255,
    'ignore_sticky_posts' => 1,
   'post__not_in' => $sticky,
   //'paged' => $paged,
    showposts=>6

);
$recent= new WP_Query( $args);
**//End sticky**
**//Display top 6 post**
while($recent->have_posts()) : $recent->the_post(); 

$postvariable++;

if ($postvariable == 1) {
 ?>
<li>[widget id="text-8"]</li>  //short code  to display sticky news
<?php  
} else { ?>
<li>
            <div class="link_contect"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a>

            </div>
    </li>
<?php
}

?>
    <?php endwhile; ?> 
//End display top 6 post
</ul>

You can see this bellow snap top first not displaying in the news.after the top post there is one another news which is i have set as sticky.Actually i want to display that 1 st top post to to 5 post after sticky news.

post

you can check my output of current code which is ignoring the first top post.

top post

1

Your variable $postvariable in while loop skips, first post. Try this,

<ul>
<li>[widget id="text-8"]</li>  //short code  to display sticky news
<?php
**//To display sticky on top** 
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$sticky= get_option( 'sticky_posts' );

$args = array(
    'cat' =>255,
    'ignore_sticky_posts' => 1,
   'post__not_in' => $sticky,
   //'paged' => $paged,
    showposts=>6

);
$recent= new WP_Query( $args);
**//End sticky**
**//Display top 6 post**
while($recent->have_posts()) : $recent->the_post(); 
 ?>



<li>
            <div class="link_contect"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a>

            </div>
    </li>
    <?php endwhile; ?> 
//End display top 6 post
</ul>
3
  • while is not closed properly while($recent->have_posts()) : $recent->the_post(); May 29 '14 at 4:58
  • @SanjayNakate Any how you got idea, why first post is skipped right? May 29 '14 at 5:01
  • great answer from me 1++ ,i think the lope was considered the first top 6 post from the sticky post what you thing is there was any other isseue May 29 '14 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.