WordPress.org

Ready to get started?Download WordPress

Forums

Sticky post isn't that sticky at all... (9 posts)

  1. daily
    Member
    Posted 5 years ago #

    Is there a bug or why I can't get this simple query_posts to show my sticky posts in my new theme? I even tried putting it in on the default theme and it still doesn't show the sticky post on top.

    <?php query_posts('cat=5,6,7'); ?>
    <?php if (have_posts()) : ?>
    
    	<?php while (have_posts()) : the_post(); ?>
    
    		<!-- post content -->
    
    	<?php endwhile; ?>
    
    <?php else : ?>
    
      	<!-- error -->
    
    <?php endif; ?>
  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    Is the sticky post in category 5, 6, or 7?

    Sticky posts are only sticky on normal blog index pages. You're reworking the query to ask for a category archive, which is something different and which is not normally where you'd want stickies to show up.

  3. daily
    Member
    Posted 5 years ago #

    Yeah sticky posts are in categories 5,6 and 7. I only want to show those categories in the frontpage (index.php). Do I misunderstand the Codex then?

    Return ALL posts with 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('caller_get_posts=1&showposts=3&cat=6');

    I get the impression that without caller_get_posts parameter sticky posts will show up at the top.

  4. t31os
    Member
    Posted 5 years ago #

    I have been trying to work this one out to, but it doesn't appear stickies take priority once you perform any custom category selection on the main page..

    The query is designed to handle stickies only on the main page as far as i can work out.. but that no longer works when you start filtering the category selection.

    Happy to be wrong if someone can show otherwise..

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    I've looked through the codebase.

    Sticky posts *only* appear on the is_home() page. Since you changed the main query to be a is_category() page, it's not an is_home() query and you don't get the stickies.

    The codex may be wrong, I have not examined it.

  6. t31os
    Member
    Posted 5 years ago #

    Perhaps a feature request is in order then...

    Category level stickies... :)

  7. poweredbysteam
    Member
    Posted 5 years ago #

    Thanks for the info. Disappointing, but good to know.

  8. kvlies
    Member
    Posted 5 years ago #

    I ran into this problem, too. I was trying to print either the most recent post or the sticky post in category 5. I came up with a solution that is probably not the most elegant in the world, but it works. Here's how I got around it:

    <?php
    $sticky=get_option('sticky_posts');
    $args=array(
       'cat'=>5,
       'post__in' => $sticky,
       'showposts'=>1,
       );
    query_posts($args);
    if (!have_posts() )
      {query_posts('cat=5&showposts=1'); }
    ?>
  9. ogonkov
    Member
    Posted 4 years ago #

    So, only way is first import all sticky posts, and then query all other non sticky?

    I will try like topic starter query posts from category to home page (index), and have no success.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.