• hi,

    I have a page where I show 2 sticky posts followed by 4 normal posts. The sticky posts use another template, so I wrote a loop that only shows the first 2 posts (the stickies) and then a normal loop to show the other posts.

    My problem: If I go to “older posts”, the 2 sticky posts aren’t present in the loop. The first 2 posts aren’t the stickies anymore.

    How can I solve this problem? I don’t ask working code. Just some intructions how I should organize my loops. ??

    Thx in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tstruyf

    (@tstruyf)

    ok, maybe I need another approach. I can make a separate category for stickies (so I dont’t use the sticky option in the wp-admin). Then I could make a different loop for both categories.

    I thought it should work like this:

    $stickies = new WP_Query(‘category_name=Stickies’);
    … Loop trough $stickies->have_posts()

    $news = new WP_Query(‘category_name=Uncategorized’);
    … Loop trough $news->have_posts()

    I’m using valid category names. Still $news and $stickies return 0 posts. Is ‘category_name’ not a valid parameter?

    Or has someone another suggestion to solve my problem?

    I haven’t done any serious work with WordPress in ages, but if you try to use an if statement, or a switch statement instead of two loops, you may find that your problem disappears. But again, I haven’t looked into it.

    Thread Starter tstruyf

    (@tstruyf)

    You mean something like this?
    if( post=sticky) : show the post ?

    I’dont think that will fix it.
    Let’s say I use the standard post-array, there will be no sticky posts in de array on page 2, 3, 4… ect. So the if-stament will just result in not displaying any sticky posts.

    Thread Starter tstruyf

    (@tstruyf)

    Ok. I found a Solution, but it is not very clean.

    My sticky posts are marked as Sticky in the WP-admin, AND they need to be in a category different from the newsitems.

    I select my sticky posts

    $stickies = new WP_Query();
     $stickies->query(array('post__in'=>get_option('sticky_posts')));

    the loop statement is like this:
    while($stickies->have_posts()):$stickies->the_post()

    The newsposts are selected this way

    query_posts('category_name=Uncategorized&paged=' . $paged .'');
    // the loop
    while(have_posts()): the_post();
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sticky post on all pages’ is closed to new replies.