Forums

sticky posts in category pages? (2 posts)

  1. Ravi
    Member
    Posted 3 years ago #

    Hi,

    website is http://www.pgmsemblog.com

    can we make a sticky post in the category archive pages?

    i read about a way to do it by adding category description. But would prefer a post to be sticky there so it is easy for editing.

    any help will be appreciated.

    Thanks

    Ravi

  2. MichaelH
    Member
    Posted 3 years ago #

    This will get one sticky post for the current category being viewed:

    <?php
    $cat = get_query_var('cat');
      $args=array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'post__in'=>get_option('sticky_posts'),
        'category__in'=> array ($cat),
        'showposts' => 1,
        'caller_get_posts'=> 1
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
         <?php
        endwhile;
      } //if ($my_query)
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags