• Resolved akis

    (@akis)


    I have the following code:

    <?php
    $sixt_id = get_catId("Blog");
    $sixt_id .= ",".get_catId("Featured");
    $sixt_id .= ",".get_catId("Premium");
    
    query_posts("showposts=6&cat=".$sixt_id);
    if (have_posts()) : while (have_posts()) : the_post();
    
    echo get_the_title();
    
    endwhile;
    endif;
    ?>

    On featured category I have a sticky post, but doesn’t show up in front, why?

Viewing 6 replies - 16 through 21 (of 21 total)
  • Get rid of the query_posts line and replace it with a filter to choose the category..

    function home_query( $query ) {
    	if( $query->is_home ) {
    		$query->set( 'category__in' , array( 1, 2, 3 ) );
    		//$query->set( 'caller_get_posts' , 1 );
    	}
    	return $query;
    }
    add_filter( 'pre_get_posts' , 'home_query' );

    Might not need the caller_get_posts parameter, can uncomment if necessary though. 1, 2 and 3 are example category IDs, replace them with the required category ID(s).

    Functions file of your theme would be a suitable place to put the code.

    Thread Starter akis

    (@akis)

    Thanks.
    I forgot to say that this is just a small part of homepage (multiple query_posts, etc). Anyway, it seems to work well but for some reason posts are limited to 5.

    Added
    $query->set( 'posts_per_page' , 6 );
    Now it displays 6+x sticky posts. I don’t really understand why it counts sticky posts separately.

    You can set that inside the filter to if you like.

    function home_query( $query ) {
    	if( $query->is_home ) {
    		$query->set( 'category__in' , array( 1, 2, 3 ) );
    		$query->set( 'posts_per_page' , 20 );
    		//$query->set( 'caller_get_posts' , 1 );
    	}
    	return $query;
    }
    add_filter( 'pre_get_posts' , 'home_query' );

    Adjust 20 to the desired amount.

    Thread Starter akis

    (@akis)

    Hah, I’ve just added a $i count in while and break after six.
    Kinda ugly but seems to work.

    Thank you so much for your help, t31os.

    Sticky posts are persistent content, they stay at the top and they appear regardless of how many posts are set to appear, they’re “stuck” in a manner of speaking, i think that’s the idea anyway.

    You’re welcome in any case.. ??

    Mark – you don’t think there’s any chance to get this working with pagination? To me, the sticky posts appear on top (very nice solution btw cheers) but they are not “counted” as parts of the pagination. What I’m trying to say is this, I have set posts_per_page to 3 but on my first page in the pagination I get 3 plus my sticky one.

    Either way, cheers for a nice solution!

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Sticky posts doesn’t work on query_posts?’ is closed to new replies.