Skip to content
Article

WordPress – Promote a Post in a Widget

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

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 /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:
[php]
add_filter(‘abt_promo_post_defaults’, ‘YOUR_HOOK’);
[/php]

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

[php]
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”>’,
);
}
[/php]

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.

capabilities covered
B2C Solutions B2B Solutions Government Higher Education What We Do IT Consulting Support

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project

Insights

Atlantic BT's Insights

We’re sharing the latest concepts in tech, design, and software development. Learn more about our findings.

Questions & Answers

Are there differences in application architecture that are important for the cloud?
It is important to build applications and workloads specifically for the cloud. You will want to carefully consider what services the cloud provider of your choice has to offer and how your application leverages those services.
Learn More about Are there differences in application architecture that are important for the cloud?
Are there any drawbacks to cloud hosting?
Yes, there will always be some risks associated with any hosting option. You are relying on the resiliency and engineering of infrastructure that has scaled at an astounding rate.
Learn More about Are there any drawbacks to cloud hosting?
What’s the benefit of hosting in the cloud vs. traditional options?
Reasons not to host in the cloud are few and far between. If you don't host in the cloud, you will spend more in both CapEx and OpEx to manage your applications or websites in a traditional environment.
Learn More about What’s the benefit of hosting in the cloud vs. traditional options?
How can I improve the performance of my application?
There are several primary reasons that applications perform poorly, and in some cases it’s a combination of several. 1) Data latency: If your application is making calls to a data source (whether it’s an API or a direct call) and there is latency at the data provider, your application performance will suffer.
Learn More about How can I improve the performance of my application?
Should I move my application to the cloud?
The answer is ‘probably yes’. There aren’t many reasons for an application to be hosted elsewhere, aside from occasional compliance standards, or requirements to integrate with local services that would require large amounts of data to move from on-premise to cloud.
Learn More about Should I move my application to the cloud?
Where should my application be hosted?
There are many different options for hosting, but most applications would do well with one of the cloud providers -- Amazon Web Services, Google Cloud Platform, Microsoft Azure.
Learn More about Where should my application be hosted?