WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

ok I'm pretty new to wordpress and the codex seems too complicated for a newbie like me. My homepage has both a slider(which I want it to display 5 latest post) and a carousel(which should display 4 older post)

I know wordpress uses the query_post() function to display the posts but my problem is how to employ this function in both the carousel and the slider (which are both on the homepage). :(

share|improve this question

You want get_posts not query_posts. Only use the latter if you need to modify the main query.

Something like this (in whatever template file you want):

<ul class="slider">
global $post;
$args = array( 'numberposts' => 5, 'order'=> 'ASC', 'orderby' => 'title' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>

Rinse, lather, repeat with necessary parameters for carousel.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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