• I already found the code to show sticky posts only elsewhere on this site but I’m not sure how to integrate it correctly into the existing code.

    Here is the loop code:

    <?php $j = 0; if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; }
    				query_posts( array( 'post_type' => array('post','reviews'), 'paged' => $paged ));
    				if (have_posts()) : while (have_posts()) : the_post();
    				?>

    …and here is the code for showing sticky posts:

    <?php if (is_home()) {
       $stickies = get_option('sticky_posts');
       if ($stickies) {
          query_posts(array_merge($wp_query->query,
                              array('post__in' => $stickies)));
       }
    }
    ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi,

    It’s almost perfect, just make sure the whole template of header.php make this same check.

    Aka <?php if (is_home()) {
    stuff;
    }

    After to follow your idea, you can just use a similiar technique on default “single.php” and “post.php” to insert a sticky post block beforehand the WP_loop.

    Hope it helps,

    Thread Starter jrcollins

    (@jrcollins)

    Thanks, but I need to know how to integrate the 2 pieces of code together. The code for the loop was copied from my theme’s template and I need to know how to apply the “sticky posts” code to the loop so it only shows sticky posts on the homepage.

    @jrcollins

    I understand, did you check if a “stick post” plugin work only on the homepage? I didn’t.

    But normally, and if WP is setup in blog mode, sticky posts only appear at the top of the front page (if again, you are in blog mode).

    Hope it helps,

    Thread Starter jrcollins

    (@jrcollins)

    Yes, but I only want to show sticky posts on the homepage.

    I don’t know which framework or theme you use, and what you want in terms of gui, but, if you use a regular theme as front page, it will display a list of lats posts and your likes as sticky in top of the list.

    Again, I dunno where exactly you wanna show the sticky posts. I think what you want is rather about theme.

    We could talk about wpbeginner.com site if you want, the all theme displays a list of sticky both at top and in widget.

    Then it’s a default post mode, in wp admin when you edit a post, clicky on “sticky”.

    If homepage is setup in blog mode, it will display your stickies at top, whatever the number of stickies. (given that by default WP loop display 10 posts on front).

    Thread Starter jrcollins

    (@jrcollins)

    I don’t know what to say. Thanks anyway!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘show sticky posts only on homepage’ is closed to new replies.