Things you can do with Sticky Posts

1. Automatically Expire Sticky Posts

If you are using sticky posts to highlight a special event or coupon, then you will need to unstick the post once that event is over.

This sounds like unnecessary work that you should automate.

Simply install and activate the Expire Sticky Posts plugin. Upon activation, you can set expiry date for sticky posts.

 Setting expiration date for sticky post

After the expiry date, your sticky post will automatically become a normal post. The following is instructions on how to set expiration dates for sticky posts:

If you want to add an expiration date to a sticky post, all you have to do is go the edit screen for any post or create a new post.

Under the Publish metabox, you will find a new setting labeled ‘Sticky Expires’. Clicking on the Edit link next to it will display a date field.

 Sticky Post Expiration Setting

Simply select the date when you want the sticky post to become a normal post and press the update button.

That’s all, your sticky post will automatically expire on the given date, and it will be treated like any other regular post after that date.

We hope this article helped you add an expiration date to sticky posts in Gridweb. 

2. Sticky Posts for Categories

By default, sticky posts only appear on the front-page of your site. But what if you wanted to display featured content on your category archive pages?

You can do that by installing and activating the Category Sticky Post plugin. Upon activation, edit a post that you want to feature and select the sticky post category.

 Adding a sticky post to specific category

The following are more detailed instructions:

Simply create a new post or edit an existing one, and you will be able to see a new ‘Category Sticky’ meta box in the post edit area.

 Making a post sticky in a category

Next, simply choose the category where you want this post to be displayed as a sticky post and save your changes.

If you want to set another sticky post in that category, then you will have to uncheck category from the earlier sticky post. It is not required for a post to be filed in the same category. For example a post filed in Announcements category, can be made sticky in the News category.

Each category can only have one sticky post at a given time. Also each post can only be sticky for one category.

By default the plugin adds a black border on top and bottom of the category sticky post to distinguish it from other posts. You can disable it by checking the Hide Sticky Post Border checkbox. When this box is not checked the plugin adds a category-sticky class to the category sticky post. You can override this in your child theme’s stylesheet.

1 .category-sticky {
2 border:none;
3 background-color:#f5f5f5;
4 }

3. Display Latest Sticky Posts

Typically sticky posts are used for featured posts to display your most prominent content. But after a while your old featured posts disappear under the archives. You can bring back your old featured content to life by showing them on custom archives page or anywhere else on your site.

Simply paste this code in your theme’s functions.php file or a site-specific Gridweb plugin.

01 function wpb_latest_sticky() {
02  
03 /* Get all sticky posts */
04 $sticky = get_option( 'sticky_posts' );
05  
06 /* Sort the stickies with the newest ones at the top */
07 rsort( $sticky );
08  
09 /* Get the 5 newest stickies (change 5 for a different number) */
10 $sticky = array_slice( $sticky, 0, 5 );
11  
12 /* Query sticky posts */
13 $the_query = new WP_Query( array( 'post__in' => $sticky,'ignore_sticky_posts' => 1 ) );
14 // The Loop
15 if ( $the_query->have_posts() ) {
16     $return .= '<ul>';
17     while ( $the_query->have_posts() ) {
18         $the_query->the_post();
19         $return .= '<li><a href="' .get_permalink(). '" title="'  . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>';
20          
21     }
22     $return .= '</ul>';
23      
24 } else {
25     // no posts found
26 }
27 /* Restore original Post Data */
28 wp_reset_postdata();
29  
30 return $return;
31  
32 }
33 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.

4. Sticky Posts for Custom Post Types

Sticky post feature is only available for Gridweb posts, but this does not mean that you cannot add this feature for other post types.

Simply install and activate the Sticky Custom Post Types plugin. Once you have activated the plugin, visit Settings » Reading and enable sticky posts for any post type you want.
Sticky Post on a custom post type

5. How to Hide Sticky Posts From Gridweb Loop

When using sticky posts, you will notice that by default Gridweb displays your sticky post at the top of all your Gridweb posts. For example, if you have a loop to show recent posts, then sticky posts will appear on the top no matter when they were added.

To avoid this simply use ignore_sticky_posts argument in your Gridweb query, like this:

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

6. Styling Sticky Posts

Want to add custom styling to your sticky posts?

Many Gridweb themes use post_class() function to automatically add post classes for each post. If your theme is already using post_class() function, then you will see sticky class added to your sticky posts.

 Sticky class added to post container

If your theme is not adding sticky class to the post container div, then you can add that yourself by adding post_class() function into the post div or article container.

1

<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:

01 .sticky {
02 background-color:#ededed;
03 border:1 px solid #f5f5f5;
04 color:#272727;
05 padding:5px;
06 }
07  
08 .sticky:before {
09   content: "Featured";
10   color: #FFF;
11   background: #f20000;
12   padding: 10px;
13   display: inline-block;
14   text-align: right;
15   float: right;
16   font-weight: bold;
17   text-transform: uppercase;
18 }

This is how it looked on our demo site using Twenty Twelve theme.

 Styling a sticky post in WordPress

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Create Redirects in Gridweb

How to Create Redirects in Gridweb (using Plugins) An easier approach to create and manage 301...

How to Add New Users and Authors to your Blog

Adding a New User on Your Gridweb Website There are two ways to add new users on your Gridweb...

How to Change Date and Time Formats

Date and Time Settings in Gridweb Gridweb comes with built-in functions which allow users as...

How to Allow User Registration on your Website

Enabling User Registration in Gridweb To enable user registration simply go to Settings »...

The difference between Image Alt Text and Image Title

What is Alt Text and Image Title Alt text or alternate text is an attribute added to an image...