0

Working on news paper site here i am using sticky.I want display first 6 sticky post its displaying very good but problem is that every sticky showing there post image(feature image) here i just want display image for the first sticky only and for other 5 sticky i want display only tittle of the post.

<ul>
<?php 

$args = array(
            'category_name' => 'महाराष्ट्र',
            'post__in' => get_option( 'sticky_posts' ),
            'showposts' => '6',

        );

$the_query = new WP_Query( $args );

    while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
  <li>      <div class="thumbnail_class"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(array(342,173), array ('class' => 'alignleft1')); ?></a></div>
        <div class="link_contect"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div><li>
      <?php 
    endwhile;

?>
</ul>
1
  • showposts is depreciated long time ago. You should be using posts_per_page Jun 19 '14 at 10:51
2

Try this :

<ul>
<?php 

$args = array(
            'category_name' => 'महाराष्ट्र',
            'post__in' => get_option( 'sticky_posts' ),
            'showposts' => '6',

        );

$the_query = new WP_Query( $args );

  $count = 1;

    while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

  <li>      
  <?php if ( 1 == $count ): ?>
<div class="thumbnail_class"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php     the_post_thumbnail(array(342,173), array ('class' => 'alignleft1')); ?></a></div>

  <?php endif ?>

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

?>
</ul>

Here count variable used for detecting first post. It is initialized to 1. In another iteration its value is increased. so if condition would be false and does not display post image.

1
  • working perfectly great answer really appreciate. +1 from me Jun 19 '14 at 10:47

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.