0

I am trying to setup a wordpress slider, how can I achieve exact below result within a wordpress loop

            <div id="carousel">
                <img src="slide1.png" alt="" class="slide" />
                <img src="slide2.png" alt="" class="slide" />
                <img src="slide3.png" alt="" class="slide" />
            </div>

            <ul id="carousel-descriptions">
                <li class="desc current">Slide 1 Description Goes Here</li>
                <li class="desc">Slide 2 Description Goes Here</li>
                <li class="desc">Slide 3 Description Goes Here</li>
            </ul>

            <div id="carousel-controls">
                <span class="control current">Show Me<br>Slide 1</span>
                <span class="control">Show Me<br>Slide 2</span>
                <span class="control">Show Me<br>Slide 3</span>
            </div>

for example, I want to show above code within

 $my_query = new WP_Query('cat=49&showposts=4&orderby=RAND');
while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;
?>

 above code

<?php endwhile; ?>

Please do let me know if there is any other way to achieve the same result but orderby=RAND is important for me

BR

2
  • is the css class .current on the first post per section important? is the image the featured imge aka post thumbnail?
    – Michael
    May 25, 2012 at 22:09
  • yes, the css class is important to show the current item highlightes. images are post thumbnail May 25, 2012 at 22:11

2 Answers 2

2

Use rewind_posts() to reset a loop and run it multiple times:

<?php

$my_query = new WP_Query('cat=49&showposts=4&orderby=RAND');
?>
<div id="carousel">
<?php
while ($my_query->have_posts()) : $my_query->the_post();
    // output each slide
endwhile;
?>
</div>
<?php

$my_query->rewind_posts();
?>
<ul id="carousel-descriptions">
<?php
while ($my_query->have_posts()) : $my_query->the_post();
    // output each desc
endwhile;
?>
</ul>
<?php

$my_query->rewind_posts();
// etc.
0
0

Or save the results into variables and run loop once like :

$carousel_descriptions .= 'Slide 1 Description Goes Here';

then after the loop its finished just echo those variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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