• I’m having some trouble understanding how to display stuff on the front page as I want to show it.

    Basically, I have a category for site updates, and on the front page I want to show the latest site update, followed by all the sticky posts that I have stickied.

    <?php
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    query_posts(‘cat=20&posts_per_page=1&paged=’ . $paged);
    while (have_posts()) : the_post();
    ?>

    so far I have that, and that shows the site update. But now the tricky part is adding somewhere either inside that code or after that code to display the sticky posts below the last post in category 20 — and only stickies.

    any help? not very good at php unfortunately.

Viewing 2 replies - 1 through 2 (of 2 total)
  • This code is UNTESTED, but should be close.

    In your first loop, you need to record the post ID so it will not be repeated in the second loop:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=20&posts_per_page=1&paged=' . $paged);
       while (have_posts()) : the_post();
          $do_not_duplicate = $post->ID;
    ?>

    Following the endwhile of your first loop, you will need a second loop for the stickies. You will need to use opening and closing php tags in the proper places to fit with the rest of the code:

    $stickies = get_option( 'sticky_posts' );
    if ($stickies) :
       $args = array(
          'posts_per_page' => -1,
          'post__in'  => $stickies,
          'ignore_sticky_posts' => 1
       );
       $my_stickies = new WP_Query( $args );
       while ($my_stickies->have_posts()) :
          $my_stickies->the_post();
          if ($post->ID == $do_not_duplicate) continue;
          // rest of the sticky loop code
       endwhile;
    endif;
    Thread Starter davepoobond

    (@davepoobond)

    whoo, that did the trick. had to interpret a couple of things, obviously, but i guessed correctly.

    very much appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show One Post from a Category and all stickies’ is closed to new replies.