是否可以在Tumblr页面上破解日期标记以显示如下帖子:
今天
昨天
周一
'今天'和'昨天'可以被周三'取代和周二'如果需要的话。
答案 0 :(得分:0)
Tumblr的模板并没有考虑分组。唯一的方法是手动(即通过javascript)对帖子进行分组,并在每个组之间创建标题。
假设jQuery简洁:
var days = {};
//group posts by day
$('.post').each(function (i, el) {
//get timestamp from post
var timestamp = new Date($(el).data('timestamp')*1000);
//set to midnight of day
timestamp.setHours(0,0,0,0);
//create array for each day if it doesn't already exist
days[timestamp] = days[timestamp] || [];
days[timestamp].push(el);
});
//now "days" will be an array of days each containing an array of posts
//print the day of the week above the first post of each day
var dayNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
$.each(days, function (dayTimestamp, dayPosts) {
//create headline with day of the week in it
var $h = $('<h1>').text(dayNames[dayTimestamp.getDay()]);
//add it before the first post of the day
$h.insertBefore(dayPosts[0]);
});
在您的模板中,请确保每封帖都有:
<div class="post" data-timestamp="{Timestamp}">...content...</div>
未经测试的代码,但它应该让你开始