WordPress.org

Ready to get started?Download WordPress

Forums

How to display the first 5 sticky posts in WP? (3 posts)

  1. jdarias
    Member
    Posted 1 year ago #

    I´m trying to display the first 5 sticky posts in WP, to create a slider. If there are no sticky post set, i want to include a file showing some dummies.

    The problem with the code i´m working is, it doesn´t distinguish the sticky posts from the normal ones. It´s broken. Can somebody lend a hand?

    Here´s the code:
    http://pastebin.com/sWfgH26Y

  2. YandexBot
    Member
    Posted 1 year ago #

    Use:

    <?php
    query_posts('showposts=5');
    if (have_posts()) {
      while (have_posts()) : the_post();
        if ( is_sticky() ) :
           the_title();
           the_excerpt();
        endif;
      endwhile;
    }
    wp_reset_query();
    ?>

    Just add your HTML-tags.
    http://codex.wordpress.org/Function_Reference/is_sticky

  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try to change this:
    if ( $entradas_slider->have_posts() ) :

    to:
    if ( $stickies && $entradas_slider->have_posts() ) :

Topic Closed

This topic has been closed to new replies.

About this Topic