We've Always Got Something to Say.

Read our thoughts on what's happening in the industry.

January 27 , 2012

WordPress – Promote a Post in a Widget

by

Here’s a WordPress plugin that will allow you to feature a single item in a widget, until you tell it to automatically expire.

Download Promoted Posts Widget v0.2  Download from WordPress

As taken from the readme file:


Description

Simple widget to display (promote) a specific post/page. Provides a list of from all public post types to choose an entry to promote until a specified date. When this “promotion” expires, you can either display a static message or use another post/page instead.


Installation

  1. Upload the plugin folder to your plugins directory /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Add the Widget “Promoted Content” to a sidebar

Frequently Asked Questions

What are the options?

  • Title: The displayed widget title – leaving it blank will use the post title (if you override the default, see Hooks)
  • Feature Expires: until what date (YYYY-MM-DD) to show the promoted post; after which fall back to the default
  • Feature Post: choose from the dropdown of public post types to promote
  • Default: display this entry instead after the expiration
  • Trim summary to: if no excerpt is provided, shorten the post content to this number of words

Note that you can select the most recent post from the dropdown options.

How can I change the defaults?

If you don’t specify certain options, the widget will use builtin defaults. Override these with the following hook:

add_filter('abt_promo_post_defaults', 'YOUR_HOOK');

where YOUR_HOOK is a function that takes an array and returns the following settings:

function promo_widget_defaults($settings){
    return array(
            #'title'        => 'Latest From MY SITE',    // disable to use post title
            'display'   => 'Check out our new video! Credit goes to ... <p><a class="archive" href="/category/news">News Archive</a></p>',
            'url'       => '#',
            'image'     => '<img src="' . get_stylesheet_directory_uri() . '/images/g_video.jpg" alt="Latest from MY SITE">',
    );
}

What else can I use?

Two static methods are available for “embedding” the widget in code – basically just the internal processing used by the widget function.

abtcore_feature_widget::display_promo($args, $before_title, $after_title) 

which uses the following

abtcore_feature_widget::get_promo($args) 

to get either the promoted post or the default. $args will contain an array of the widget options (title, expire, promo, default, trim).

Function get_promo will return an array of (title, display, url, and image) to display_promo where it gets combined with the defaults from the hook to output the widget HTML.

About the Author

Jeremy Schwartz is a software developer with a broad range of programming experience from research, consulting, and academic settings. His favorite thing to do is refactor inefficient code into well-documented, elegant solutions using content-management systems and custom code. Or read books. Lots of books.

Leave a Reply

 

In a Nutshell

Since 1998, Atlantic BT has been a full service web development company that offers the tools, resources and services to get your business moving. We focus on combining new ideas, specific requirements, and years of experience into high-quality, results-oriented web solutions for small to medium sized businesses. If you want the best website possible that generates real results, let's get started.

Atlantic Business Technologies, Inc.
4509 Creedmoor Road, 3rd Floor
Raleigh, North Carolina 27612
  • Pinnacle Business Award Winner
  • Triangle Business Journal's Top 40 Under 40
  • Yahoo Search Marketing Ambassador
  • Google Adwords Qualified Company