Beginner’s GuideBlog

6 Cool Things You Can Do With Sticky Posts in WordPress

Do you know that WordPress permits you to function your posts by utilizing sticky posts function. Nevertheless, sticky posts are one of many least identified options of WordPress. On this article, we’ll present you 6 cool issues you are able to do with sticky posts in WordPress.

Sticky Post Tricks

1. Mechanically Expire Sticky Posts

In case you are utilizing sticky posts to focus on a particular occasion or coupon, then you have to to unstick the submit as soon as that occasion is over.

This appears like pointless work that it is best to automate.

Merely set up and activate the Expire Sticky Posts plugin. Upon activation, you possibly can set expiry date for sticky posts.

Setting expiration date for sticky post

After the expiry date, your sticky submit will mechanically develop into a standard submit. For detailed directions check out our tutorial (with video) on easy methods to set expiration date for sticky posts in WordPress.

2. Sticky Posts for Classes

By default, sticky posts solely seem on the front-page of your web site. However what when you needed to show featured content material in your class archive pages?

You are able to do that by putting in and activating the Class Sticky Publish plugin. Upon activation, edit a submit that you simply wish to function and choose the sticky submit class.

Adding a sticky post to specific category

For extra detailed directions, see our tutorial on easy methods to add sticky posts for classes in WordPress.

3. Show Newest Sticky Posts

Usually sticky posts are used for featured posts to show your most outstanding content material. However after some time your previous featured posts disappear underneath the archives. You possibly can convey again your previous featured content material to life by displaying them on customized archives web page or anyplace else in your web site.

Merely paste this code in your theme’s features.php file or a site-specific WordPress plugin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
perform wpb_latest_sticky() {
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );
/* Kind the stickies with the latest ones on the prime */
rsort( $sticky );
/* Get the 5 latest stickies (change 5 for a special quantity) */
$sticky = array_slice( $sticky, 0, 5 );
/* Question sticky posts */
$the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
// The Loop
if ( $the_query->have_posts() ) {
    $return .= '<ul>';
    whereas ( $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 discovered
}
/* Restore unique Publish Information */
wp_reset_postdata();
return $return;
}
add_shortcode('latest_stickies', 'wpb_latest_sticky');

After including this code, merely create add the shortcode [latest_stickies] wherever you wish to show your newest sticky posts.

For detailed directions, go to our article: Easy methods to show newest sticky posts in WordPress.

4. Sticky Posts for Customized Publish Sorts

Sticky submit function is barely obtainable for WordPress posts, however this doesn’t imply that you simply can’t add this function for different submit varieties.

Merely set up and activate the Sticky Custom Post Types plugin. Upon getting activated the plugin, go to Settings » Studying and allow sticky posts for any submit sort you need.

Sticky Post on a custom post type
For extra detailed directions try our tutorial on easy methods to add sticky posts in WordPress customized submit varieties.

5. Easy methods to Cover Sticky Posts From WordPress Loop

When utilizing sticky posts, you’ll discover that by default WordPress shows your sticky submit on the prime of all of your WordPress posts. For instance, if in case you have a loop to point out current posts, then sticky posts will seem on the highest regardless of after they have been added.

To keep away from this merely use ignore_sticky_posts argument in your WordPress question, like this:

1
2
3
4
5
6
7
8
<?php
$args = array(
    'posts_per_page' => 10,
    'ignore_sticky_posts' => 1
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : whereas ( $the_query->have_posts() ) : $the_query->the_post();
?>

See our tutorial on easy methods to exclude sticky posts from WordPress loop for extra detailed directions.

6. Styling Sticky Posts

Wish to add customized styling to your sticky posts?

Many WordPress themes use post_class() perform to mechanically add submit lessons for every submit. In case your theme is already utilizing post_class() perform, then you will notice sticky class added to your sticky posts.

Sticky class added to post container

In case your theme isn’t including sticky class to the submit container div, then you possibly can add that your self by including post_class() perform into the submit div or article container.

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

Now you should utilize the .sticky CSS class in your little one theme‘s stylesheet. Right here is a few primary CSS to get you began:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.sticky {
background-color:#ededed;
border:1 px stable #f5f5f5;
colour:#272727;
padding:5px;
}
.sticky:earlier than {
  content material: "Featured";
  colour: #FFF;
  background: #f20000;
  padding: 10px;
  show: inline-block;
  text-align: proper;
  float: proper;
  font-weight: daring;
  text-transform: uppercase;
}

That is the way it appeared on our demo web site utilizing Twenty Twelve theme.

Styling a sticky post in WordPress

That’s all, we hope this text helped you study some cool issues to do with sticky posts in your WordPress web site. You might also wish to try our information on 10 most needed class hacks and plugins for WordPress.

Download The WPSaviour App Now

Related posts
BlogTutorials

How to Add Sticky Posts in WordPress Custom Post Type Archives

BlogThemes

How to Exclude Sticky Posts from the Loop in WordPress

Beginner’s GuideBlog

How to Make Sticky Posts in WordPress

Leave a Reply

Your email address will not be published.

Pay in your preferred currency
Indian rupee
Euro