1

I have parent category is Game cat_id=42. Child categories are : acrade, causual,.... I want show a top game module in mainpage template, it will show 10 sticky post from game category.

This my code :

<?php 
   $args = array(
      'cat' => 42,
      'posts_per_page' => 10,
      'post__in'  => get_option( 'sticky_posts' ),
   );
   query_posts( $args );
?>

1 Answer 1

2

Use the below code in the mainpage template to show the sticky posts.

<?php 
$args = array(
    'cat'            => 42,
    'posts_per_page' => 10,
    'post__in'       => get_option( 'sticky_posts' ),
);
// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo '<li>' . get_the_title() . '</li>';
}

The above will print the title of the sticky posts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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