WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have styled an archive page to display one sticky post at the top with special design, and then to display all the rest of the posts in that category (except the sticky post) listed in standard title/excerpt format. I have specified the target category for both loops:

Sticky only:

<?php $args = array(
'cat' => 3,
'posts_per_page' => 1,
'post__in'  => get_option( 'sticky_posts' ),
'ignore_sticky_posts' => 1              
    );

query_posts( $args );?>

All the rest:

<?php 
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$sticky = get_option( 'sticky_posts' );                     
$args = array(
    'cat' => 3,
    'ignore_sticky_posts' => 1,
    'post__not_in' => $sticky,
    'paged' => $paged,
    'orderby' => 'menu_order',  
    'order' => 'ASC' 
); 
query_posts( $args ); ?>

I have made custom category.php templates for each category with the 'cat' ID added manually in each loop.

My question: Is it possible to do this without manually setting the cat ID? I have tried but end up with all posts rather than just the category variable. thx - Steve

share|improve this question

you can get the category ID of a category archive with:

get_query_var('cat')
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.