Reblog via Tom Finley
Can anyone see this post?
The post appeared first on Tom Finley.
I can see this post! Thanks for your Narwhal plugin 🙂 Is there any chance of a post explaining how you built this site? The ‘2 hours/3 weeks ago’ dating for example, and your Activity post format? Would be incredibly grateful!
Hello! The human readable time is done with a plugin. Meks Time Ago: https://wordpress.org/plugins/meks-time-ago/
You can instead update your theme files and use the following code but the plugin is nice and easy.
Example code for theme versus using the plugin:
$post_date = get_the_date();
$post_timestamp = strtotime($post_date);
$now = time();
$diff = $now - $post_timestamp;
if ($diff < 604800) {
echo human_time_diff($post_timestamp, $now) . ' ago';
} elseif ($diff < 2419200) {
$weeks = floor($diff / 604800);
echo $weeks . ' week' . ($weeks > 1 ? 's' : '') . ' ago';
} elseif ($diff < 31536000) {
$months = floor($diff / 2419200);
echo $months . ' month' . ($months > 1 ? 's' : '') . ' ago';
} else {
$years = floor($diff / 31536000);
echo $years . ' year' . ($years > 1 ? 's' : '') . ' ago';
}
The activity feed is BuddyPress. Although a little overkill, I wanted an activity stream and didn’t want to create it from scratch. So, I installed BuddyPress but deactivated most features. I also don’t use the BuddyPress login, register, or profile pages.
And your live link previews! Beautiful 🙂
I see it
Leave a Reply