Sticky Post Function Not Working. Please Help?
-
Hi guys. I’m having an issue with sticky posts not working correctly in a custom theme which I’m developing (I’m still kinda new to building themes from scratch).
I would like all sticky posts to show up first on the home page, followed by normal posts. Here is my index.php code:
<?php get_header(); ?> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_sidebar(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="time-and-date"> <div class="post-date"> <div class="post-date"><span class="date-icon"></span><?php the_time( 'l, F j, Y' ); ?></div> </div> <div class="post-time"> <div class="post-time"><?php the_time( 'h:i A, T' ); ?><span class="time-icon"></span></div> </div> </div> <a href="<?php the_permalink(); ?>"><?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail(); ?></a> <div class="post-title"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div> <div class="post-content"> <?php the_content(); ?> <?php wp_link_pages(); ?> </div> <div class="post-sharing"></div> <div class="post-meta"><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Permalink</a> | Comments | <a href="https://www.addthis.com/bookmark.php" target="_blank">Share</a></div> <div class="post-categories"><span class="post-tags"><?php the_tags( 'Tags: ', ' ', ''); ?></span></div> </div> <?php endwhile; /* rewind or continue if all posts have been fetched */ ?> <?php else : ?> <?php endif; ?> </div> <?php get_footer(); ?>
If you go to https://dev.davidventer.net/wordpress and scroll down, you will see a post titled ‘Layout Test’. This is a sticky post which is supposed to show up before all other posts on the home page, but it does not.
I’ve googled around a bit and found some blogs saying that I need to have a sticky class in my CSS in order for the stickies to show up first. I have the following in my CSS:
.sticky { background: #ffffff; }
I’m probably just missing something basic here which I’ve overlooked. Maybe there is something I need to put in my functions.php? or some other small php call which I’m missing from my loop? I don’t know. It’s driving me nutty. Please help!
- The topic ‘Sticky Post Function Not Working. Please Help?’ is closed to new replies.