• Resolved nadine00

    (@nadine00)


    Hi,

    I’m making a category template…and I’m trying to figure out how to pull a sticky post only if that post is in the current category. So basically:

    If ‘post’ is in ‘category-x’ & marked as sticky, display it.

    I was trying something with

    ‘post__in’ => get_option(‘sticky_posts’),

    …but whenever i have two categories with stickies, it jumbles them up. Suggestions?

    Thanks!

    Nadine.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter nadine00

    (@nadine00)

    Hmm, ok i think this plugin will do it: https://www.ads-software.com/extend/plugins/astickypostorderer/

    However out of curiosity, is there a way to do it natively with a query in wordpress? Something like:

    loop through posts in this category -> if there is a post in ‘current category’ & ‘is a sticky’ then display it at the top, and limit it to 1

    Suggestions or tutorial links?

    Thanks!

    Nadine

    Thread Starter nadine00

    (@nadine00)

    hi esmi,

    I’ve referenced that page a few times, its been very helpful, but this time, I’m unsure about how to join current category & is sticky into a query. eg:

    $current_category = category ID in a variable
    
    <?php array=$sticky(
    caller_get_posts=1,
    post__in => $current_category && get_option("sticky_posts"),
    posts_per_page=1
    );
    ?>
    
    <?php array=$sticky(
    caller_get_posts=1,
    post__in => array($current_category, 'sticky_posts';),
    posts_per_page=1
    );
    ?>
    
    ?<php query_posts('caller_get_posts=1&posts_per_page=1&category=$current_category&get_option("sticky_posts")'); ?>

    They either come back blank, or pull all the posts across the board marked with sticky. I know I’m combining things improperly, I am just unsure of the proper way to do it. Sorry for the questions….the combining of items always gets me in WP. ??

    Or maybe there’s a way to use is_sticky() ?

    _n

    Ah – I see the problem. I think it would be easiest to grab all stickies and then loop through to see if any of them are in your chosen category using in_category().

    Thread Starter nadine00

    (@nadine00)

    Got it.

    <?php $sticky = array(
    	'post__in'  => get_option('sticky_posts')
    );?>
    
    		<?php query_posts($sticky);	?>	
    
    			<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
    
    				if(in_category($current_cat)) {?>
    
    					<?php the_content(); ?>
    
    				<?php } ?>
    
    			<?php endwhile; else: ?>
    			<?php endif; ?>

    Thanks so much for your suggestion. ??

    Nadine.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sticky post from only current category’ is closed to new replies.