WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category Sticky (5 posts)

  1. picard102
    Member
    Posted 5 years ago #

    So here is what I'm trying to do.

    On the category archive pages I want to have sticky posts in that category appear at the top of the page and the paginated pages, and then follow that with the normal display of posts and pagination for that category.

    I figured I could do this with a post query to call the sticky, and then another query after to display the normal order of posts.

    I can't seem to get the code quite right though. Anyone know of a better solution, or the right php to use to make this work?

  2. MichaelH
    Member
    Posted 5 years ago #

    This in a Category Template works to show the sticky posts for a given category:

    <?php
    $cat = get_query_var('cat');
    $sticky=get_option('sticky_posts');
    $args=array(
      'post__in' => $sticky,
      'category__in'=>array($cat)
       );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
        <?php
        the_content();
        //this is necessary to show the tags
        global $wp_query;
        $wp_query->in_the_loop = true;
        the_tags();
      endwhile;
    }
    ?>
  3. Frank Anthony
    Member
    Posted 4 years ago #

    Whats the easiest way to make posts Sticky for a category separate from the home page. I know I can hard code which post numbers I don't want to show, but that's not really an option I like.

    I have only one post I want sticky for the home page but other posts I want sticky in their category pages.

    Do we still need a plugin to accomplish this?

  4. Superhearing
    Member
    Posted 4 years ago #

    I am looking for the same thing.

  5. invisibleillness
    Member
    Posted 4 years ago #

    I'm looking too

Topic Closed

This topic has been closed to new replies.

About this Topic