• l r

    (@lainyrache)


    I have the following on my home page which does all I need –
    Except:
    My sticky posts now fall to the bottom of the loop. Does anyone know the neatest way to regain my stickies at the top of the page.. many thanks
    Thanks!
    <?php $my_query = new WP_Query(‘category_name=featured&showposts=5’);
    $counter=0; while ($my_query->have_posts()) : $my_query->the_post(); $counter++;
    $do_not_duplicate = $post->ID;?>
    <div <?php post_class(); id=”post-<?php the_ID(); ?>”>
    <?php if ($counter > 1) ?>
    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></h2>
    <div class=”post” id=”post-<?php the_ID(); ?>”>
    <?php
    if ($counter < 1) {
    the_content(”);
    } else {
    the_excerpt(”);
    }
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • In addition to displaying sticky post(s) first, that’s the goal here?

    Here’s my guess:
    1. Get 5 posts in the category=featured, and the sticky posts.
    2. On the first of those posts display the_content and on the rest display the_excerpt.

    Question:
    When displaying the sticky posts, what displays–the_content or the_excerpt?

    Thread Starter l r

    (@lainyrache)

    Hi Sorry – I was not very clear.

    Thanks for getting back to me.

    1. Yes I want 5 posts from category=featured, some will be stickies, the stickies should be at the top.

    2. All posts display either
    full content or shortened content via the more tag
    or if excerpt exists show a bespoke excerpt.

    I am hard coding the ‘read more of this entry >>’
    It’s not ideal but I couldn’t get it to link to the full content consistently.
    When the sticky displays – I have the excerpt or the content whichever exists.

    Well you can play with this:

    <?php
    $cat=get_cat_ID('featured');
    $posts=get_posts(array('post__in'=>get_option('sticky_posts')));  // get sticky posts
    if ($posts) {
      foreach($posts as $post) {
        setup_postdata($post);
        if ( in_category($cat) ) { // only sticky posts in selected category
          ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
          the_content('Read the rest of this entry &raquo;');
        }
      }
    }
    $posts=get_posts(array('post__not_in'=>get_option('sticky_posts'),'cat'=>$cat,'showposts'=>5));  //get posts in our category, exclude sticky posts
    if ($posts) {
      foreach($posts as $post) {
        setup_postdata($post);
        ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content('Read the rest of this entry &raquo;');
      }
    }
    ?>

    Needed two loops, one to process the sticky posts in your category, then another to process the non-sticky posts.

    Thread Starter l r

    (@lainyrache)

    Hi Michael…
    quick test ..it kind of does it – need to mess around… will get there..
    Thank you..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can i call a sticky to the top of this loop’ is closed to new replies.