Skip links

All you want to know about sticky posts on WordPress

After you made the blog like we said in this article, you need to attract the more possible visitors to your content. You may write a post and you observe that the visitors come back to it again and again. At this moment you need to pin this post to attract more people and this it the topic of this article about sticky posts.

What is sticky post?

A sticky post is a blog post that stays at the top of your blog’s main archive page even if other blog posts are published after it.

As you add posts to a WordPress site, older posts gradually rotate off the main screen into the archives. You may find  that you have some posts that are a hybrid of a post and a page. They are best represented as posts but you need that the content they contain to not be date sensitive and you always want them displayed at the beginning, regardless of the date published. These are called “sticky posts” because they are “stuck” to the front page of the site.

How to make sticky posts?

You can find how to make the post sticky like in the image below inside the visibility options. Just check the check box in “Stick this post to the front page” and don’t forget the click “OK”

how_to_add_sticky_posts

How to make sticky post for each category?

The previous step was for the front page of the website only. What if you want to make sticky post for each category or page on WordPress website? in this situation, you need to install specific plugin called Category Sticky Post.

This plugin has no configurable settings. All you have to do once it is installed and activated is use the new meta box that appears in your post editor.

Once you made that, you made that, you can create sticky posts as you want.

More tips about sticky posts

1.Display latest sticky posts

During the improvements of the content on the website your featured posts may be erased from the sight of the visitors. You can make them a live again by showing them on custom archives page or anywhere else on your site.

Simply paste this code in your theme’s functions.php file.

function wpb_latest_sticky() {

/* Get all sticky posts */

$sticky = get_option( ‘sticky_posts’ );

/* Sort the stickies with the newest ones at the top */

rsort( $sticky );

/* Get the 5 newest stickies (change 5 for a different number) */

$sticky = array_slice( $sticky, 0, 5 );

/* Query sticky posts */

$the_query = new WP_Query( array( ‘post__in’ => $sticky, ‘ignore_sticky_posts’ => 1 ) );

// The Loop

if ( $the_query->have_posts() ) {

$return .= ‘<ul>’;

while ( $the_query->have_posts() ) {

$the_query->the_post();

$return .= ‘<li><a href=”‘ .get_permalink(). ‘” title=”‘  . get_the_title() . ‘”>’ . get_the_title() . ‘</a><br />’ . get_the_excerpt(). ‘</li>’;

 

}

$return .= ‘</ul>’;

 

} else {

// no posts found

}

/* Restore original Post Data */

wp_reset_postdata();

return $return;

}

add_shortcode(‘latest_stickies’, ‘wpb_latest_sticky’);

After adding this code, simply create add the shortcode [latest_stickies] wherever you want to display your latest sticky posts.

2.Adding style to sticky posts

You can add special style and formatting to sticky posts to give them more attention.

In this case, you need to add some lines of code to your theme and don’t panic ae will explain it clearly.

you can add post_class() function into the post div or article container.

<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

Now you can use the .sticky CSS class in your child theme‘s stylesheet. Here is some basic CSS to get you started:

.sticky {

background-color:#ededed;

border:1 px solid #f5f5f5;

color:#272727;

padding:5px;

}

We hope that article helps you  a bit. Tell us about your experience with sticky posts.

 

Leave a comment

Explore
Drag