Monday, 20 May 2013

How to display a sticky post inside a div?

How to display a sticky post inside a div?

I have a and inside it I would like to add the contents of the first sticky post.
I went on codex.wordpress.org to find more about wp_query and saw this code that I could use to solve my problem:
$sticky = get_option( 'sticky_posts' );
$args = array(
    'posts_per_page' => 1,
    'post__in'  => $sticky,
    'ignore_sticky_posts' => 1
);
$query = new WP_Query( $args );
if ( $sticky[0] ) {
    // insert here your stuff...
}
What I don't know is if this is what I am looking for and if yes, what do I need to add in the if statement in order for this code to display the first sticky post inside my div? Thanks in advance!

No comments:

Post a Comment