How to reduce the database query-es

The question:

Hy, i make a slide for news, the question is how can i reduce the dathabase queries…ore how can i compress this code…

http://s16.postimage.org/bswe0vrph/queries.jpg

<div id="featured" >
<ul class="ui-tabs-nav">

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array( 
    'post_type' => 'stiri',
    'showposts' => 1,
    'offset'=>0,
    'taxonomy' => 'stire',
    'stire' => 'articole-speciale'
    )
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-1" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=50&amp;w=80&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-2">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array( 
    'post_type' => 'stiri',
    'showposts' => 1,
    'offset'=>1,
    'taxonomy' => 'stire',
    'stire' => 'articole-speciale'
    )
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-2" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=50&amp;w=80&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-3">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array( 
    'post_type' => 'stiri',
    'showposts' => 1,
    'offset'=>2,
    'taxonomy' => 'stire',
    'stire' => 'articole-speciale'
    )
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-3" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=50&amp;w=80&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-4">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array( 
    'post_type' => 'stiri',
    'showposts' => 1,
    'offset'=>3,
    'taxonomy' => 'stire',
    'stire' => 'articole-speciale'
    )
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-4" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=50&amp;w=80&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>

<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-5">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array( 
    'post_type' => 'stiri',
    'showposts' => 1,
    'offset'=>4,
    'taxonomy' => 'stire',
    'stire' => 'articole-speciale'
    )
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-5" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=50&amp;w=80&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>
          </ul>

        <!-- Stirea 1  -->
        <div id="fragment-1" class="ui-tabs-panel" style="">
        <?php
        $recentPosts = new WP_Query();
        $recentPosts->query(array( 
       'post_type' => 'stiri',
       'showposts' => 1,
       'taxonomy' => 'stire',
       'stire' => 'articole-speciale'
                )
            );
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
            <a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=325&amp;w=664&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
             <div class="info" >
                <h2><a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><?php the_title(); ?></a></h2>
                <p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="bookmark" title="<?php printf(__('Stire %s'), the_title_attribute('echo=0')); ?>">...detalii</a></p>
             </div>
        <?php endwhile; ?>
        </div>

        <!-- Stirea 2  -->
        <div id="fragment-2" class="ui-tabs-panel ui-tabs-hide" style="">
        <?php
        $recentPosts = new WP_Query();
        $recentPosts->query(array( 
       'post_type' => 'stiri',
       'showposts' => 1,
       'offset'=>1,
       'taxonomy' => 'stire',
       'stire' => 'articole-speciale'
                )
            );
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
            <a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=325&amp;w=664&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
             <div class="info" >
                <h2><a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><?php the_title(); ?></a></h2>
                <p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="bookmark" title="<?php printf(__('Stire %s'), the_title_attribute('echo=0')); ?>">...detalii</a></p>
             </div>
        <?php endwhile; ?>
        </div>

        <!-- Stirea 3  -->
        <div id="fragment-3" class="ui-tabs-panel ui-tabs-hide" style="">
        <?php
        $recentPosts = new WP_Query();
        $recentPosts->query(array( 
       'post_type' => 'stiri',
       'showposts' => 1,
       'offset'=>2,
       'taxonomy' => 'stire',
       'stire' => 'articole-speciale'
                )
            );
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
            <a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=325&amp;w=664&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
             <div class="info" >
                <h2><a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><?php the_title(); ?></a></h2>
                <p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="bookmark" title="<?php printf(__('Stire %s'), the_title_attribute('echo=0')); ?>">...detalii</a></p>
             </div>
        <?php endwhile; ?>
        </div>

        <!-- Stirea 4  -->
        <div id="fragment-4" class="ui-tabs-panel ui-tabs-hide" style="">
        <?php
        $recentPosts = new WP_Query();
        $recentPosts->query(array( 
       'post_type' => 'stiri',
       'showposts' => 1,
       'offset'=>3,
       'taxonomy' => 'stire',
       'stire' => 'articole-speciale'
                )
            );
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
            <a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=325&amp;w=664&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
             <div class="info" >
                <h2><a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><?php the_title(); ?></a></h2>
                <p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="bookmark" title="<?php printf(__('Stire %s'), the_title_attribute('echo=0')); ?>">...detalii</a></p>
             </div>
        <?php endwhile; ?>
        </div>

        <!-- Stirea 5  -->
        <div id="fragment-5" class="ui-tabs-panel ui-tabs-hide" style="">
        <?php
        $recentPosts = new WP_Query();
        $recentPosts->query(array( 
       'post_type' => 'stiri',
       'showposts' => 1,
       'offset'=>4,
       'taxonomy' => 'stire',
       'stire' => 'articole-speciale'
                )
            );
        ?>
        <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
            <a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=325&amp;w=664&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
             <div class="info" >
                <h2><a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><?php the_title(); ?></a></h2>
                <p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="bookmark" title="<?php printf(__('Stire %s'), the_title_attribute('echo=0')); ?>">...detalii</a></p>
             </div>
        <?php endwhile; ?>
        </div>

</div>

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You can try this version with WP_Query() called only once:

<?php
$args=array( 
    'post_type' => 'stiri',
    'posts_per_page' => 5,
    'taxonomy' => 'stire',
    'stire' => 'articole-speciale'
    );
$recentPosts = new WP_Query($args);
?>
<div id="featured" >
    <ul class="ui-tabs-nav">
        <?php $i=0; while ($recentPosts->have_posts()) : $recentPosts->the_post(); $i++;?>
            <li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-<?php echo $i;?>">
                <a href="#fragment-<?php echo $i;?>" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=50&amp;w=80&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
            </li>
        <?php endwhile; ?>
    </ul>

    <?php $recentPosts->rewind_posts();?>

    <?php $i=0; while ($recentPosts->have_posts()) : $recentPosts->the_post(); $i++; ?>    
        <!-- Stirea <?php echo $i;?>  -->
        <div id="fragment-<?php echo $i;?>" class="ui-tabs-panel" style="">
            <a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><img src="/scripts/timthumb.php?src=<?php the_field('imagine_stire'); ?>&amp;h=325&amp;w=664&amp;zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
            <div class="info" >
                <h2><a href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"><?php the_title(); ?></a></h2>
                <p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="bookmark" title="<?php printf(__('Stire %s'), the_title_attribute('echo=0')); ?>">...detalii</a></p>
            </div>
        </div>
    <?php endwhile; ?>
</div>

where $recentPosts->rewind_posts() is used to rewind before the second loop.

Method 2

<div id="featured" >
  <ul class="ui-tabs-nav">

  <?php
    // shange 1 --> category ID 
    $cat=1;
    $recentPosts = new WP_Query();
    $recentPosts->query("showposts=1&cat=$cat");
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); 
  ?>

  <li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-<?php the_ID(); ?>">
    <a href="#fragment-<?php the_ID(); ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">
      <img src="<?php $values = get_post_custom_values("slider"); echo $values[0]; ?>"  alt="" width="80px" height="50px" />
      <span><?php the_title();?></span>
    </a>
  </li>

  <?php endwhile; ?>

  <?php 
    $recentPosts = new WP_Query( array( 'offset' => 2 ) );
    $recentPosts->query("showposts=3&cat=$cat&offset=1");
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); 
  ?>  

  <li class="ui-tabs-nav-item" id="nav-fragment-<?php the_ID(); ?>">
    <a href="#fragment-<?php the_ID(); ?>" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">
      <img src="<?php $values = get_post_custom_values("slider"); echo $values[0]; ?>"  alt="" width="80px" height="50px" />
      <span><?php the_title();?></span>
    </a>
  </li>

  <?php endwhile; ?>

  </ul>

  <!-- First Content -->

  <?php
    // shange 1 --> category ID 
    $cat=1;
    $recentPosts = new WP_Query();
    $recentPosts->query("showposts=1&cat=$cat");
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); 
  ?>

  <div id="fragment-<?php the_ID(); ?>" class="ui-tabs-panel" style="">
    <img src="<?php $values = get_post_custom_values("slider"); echo $values[0]; ?>"  width="400px" height="250px" alt="" />
    <div class="info" >
      <a class="hideshow" href="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" >Hide</a>
      <h2><a href="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" ><?php the_title();?></a></h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" >read more</a></p>
    </div>
  </div>

  <?php endwhile; ?>

  <!-- Second Content -->

  <?php 
    $recentPosts = new WP_Query( array( 'offset' => 2 ) );
    $recentPosts->query("showposts=3&cat=$cat&offset=1");
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); 
  ?>  

  <div id="fragment-<?php the_ID(); ?>" class="ui-tabs-panel ui-tabs-hide" style="">
    <img src="<?php $values = get_post_custom_values("slider"); echo $values[0]; ?>" width="400px" height="250px"  alt="" />
    <div class="info" >
      <a class="hideshow" href="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" >Hide</a>
      <h2><a href="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" ><?php the_title();?></a></h2>
      <p>Vestibulum leo quam, accumsan nec porttitor a, euismod ac tortor. Sed ipsum lorem, sagittis non egestas id, suscipit....<a href="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener" >read more</a></p>
    </div>
  </div>

  <?php endwhile; ?>

</div>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment