A timeline is a display of a list of events in chronological order. It is typically a graphic design showing a long (normally horizontal) bar labelled with dates alongside itself with (what is usually) events. If perfect visual representation is your thing, the distance between each element on the timeline itself is graphed appropriately to represent the time between each event. Our article will show you how to build a basic timeline with WordPress shortcode.
See also: "Create a Modal Popup Timeline With WordPress Shortcode or PHP" here.
In the news and WordPress world of real-time blogging, the timeline is often used a a visual indication for each component of a series, or an ongoing or developing news story. For that reason, our timeline will render posts based on a tag ... although you might just as easily obtain data from anywhere and curate it in the manner as described below. We chose WP post tags simply for the purpose of the demonstration.
The Result
While it serves virtually no purpose, we've chosen to display posts tagged with youtube as if the series were a developing story that we were live-blogging. The result of [timeline tags="youtube"]
is as follows (we've returned only the last 5 posts to save space):
If you're on a mobile device it's likely you're seeing the entire response in a single column.
If we chose not to alternate the containers, and this time changing the colors slightly, we might use [timeline tags="youtube" background="#09A3E2" alternating="0" number="3" vertical="#000000" dot="#09A3E2"]
. The result:
WordPress Shortcode
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
We use Simple Cache to cache the resulting HTML. Install via this page. You can alternatively alter our cache functions for the WP transient API.
If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.
Shortcode Attributes
While there's a large number of attributes, most of them are of the set-and-forget variety.
tags
descending
descending="0"
to return the results in reverse chronological order.posttype
image_size
alternate
alternate="0"
.ruler
titlesize
number
-1
which returns them all.date & format
description
description="0"
.words
words
is the number of words the description is truncated.remove
responsive
responsive
attribute determines at what viewport the timeline reverts to a mobile responsive view.background
vertical
dot
textcolor
cache
Considerations
- We've used Font Awesome for icons. If your WP theme doesn't support FA by default, download and include from the FA website (or use HTML entities/images for the calendar and right arrow icon). Use the CloudFlare hosted version with the code below.
- We've used inline CSS which is far from best practice. However, it does cater for numerous occurrences of the timelines with alternate styles on the same page. If you're using a single style, copy the CSS and code into their respective files.
- We haven't included the title in the response. Include the
$title
variable if you choose to show it. - The shortcode is similar to our series shortcode with the exception that we've limited the search parameters and styled the output.
Download
Title: Create a Basic Timeline With WordPress Shortcode
Description: Create a basic timeline with WordPress shortcode. Includes a staggered and inline option. Formatting options apply.
Download • Version 0.1, 2.6K, zip, Category: WordPress Shortcodes