Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Tuesday, February 15, 2011

Wordpress Codex: Exclude Sticky Posts From Query

Exclude all sticky posts from the query:
query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );

Exclude sticky posts from a category. Return ALL posts within the category, but don't show sticky posts at the top. The 'sticky posts' will still show in their natural position (e.g. by date):
query_posts( 'ignore_sticky_posts=1&posts_per_page=3&cat=6' );

Thursday, September 23, 2010

WordPress Codex: Limit Query Posts Per Page

//The Query
query_posts('posts_per_page=5');

//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
..
endwhile; else:
..
endif;

//Reset Query
wp_reset_query();
?>

Wordpress Codex: Return Just The First Sticky Post

First Method
This methode return first sticky post ASC ordered
$sticky=get_option('sticky_posts') ;
query_posts('p=' . $sticky[0]);

Second Method
This method return first sticky post DESC ordered.
If there are not sticky posts, it returns the last post published.
$args = array(
'posts_per_page' => 1,
'post__in' => get_option('sticky_posts'),
'caller_get_posts' => 1
);
query_posts($args);

Source