4

In my theme, I'm using front-page.php for the static front page. I'm also using a page to store the content on the static front page. The front-page.php file is set up to show the content from that page.

However, in the front-page.php file, I also want to show all of my blog's sticky posts below that content. How would I do that?

2

Something like this should work:

$sticky = get_option( 'sticky_posts' );
if ( !empty( $sticky ) ) {  // don't show anything if there are no sticky posts
    $args = array(
        'posts_per_page' => -1,  // show all sticky posts
        'post__in'  => $sticky,
        'ignore_sticky_posts' => 1
    );
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) {
        $query->the_post();
        // display your sticky post here (however you like to do it)
    }
}

You should place this in your front-page.php file. It will select all sticky posts and show them.

1
  • 1
    Make sure to also add a wp_reset_postdata(); after your if statement to reset the $post global to the main query.
    – jjeaton
    Aug 7 '13 at 15:15

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.