0

Interesting challenge. I was given a piece of code earlier, which I have modified as follows for the Posts page.

/* add time stamp */
add_filter('manage_posts_columns', 'posts_columns', 5);
function posts_columns($defaults){
    $defaults['your_date_col'] = __('Date');
    $defaults['week_number'] = __('Wk#');
    $defaults['week_in_quarter'] = __('Wk/Qtr');
    return $defaults;
}
add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2);
function posts_custom_columns($column_name, $id){
    if($column_name === 'your_date_col'){
    echo the_date('d M'),' ',the_time('Ha');
    }
    if($column_name === 'week_number'){
    echo 'Here: ',the_date();
    }
}

Strangely, although the date format that I have given shows up in the first column ("your_date_col"), only "Here: " shows up in the second column ("week_number"). Any suggestions as to why the_date function doesn't work in the second column?

3
  • 2
    I've found the_date() to always behave strangely, I believe there's a note about it in the codex. I use get_the_date() or the_time() instead.
    – Milo
    Jun 3 '11 at 20:06
  • I was just coming here to write that up. I realized that in the browse menu, for some reason some of the dates were only showing a time - because the date had already been shown on a previous post. Switching to get_the_date works. Thanks. Jun 3 '11 at 20:28
  • But I don't know how to mark this as answered. Jun 3 '11 at 20:28
1

1) the_date() echoes the date value, so this statement isn't correct:

echo the_date('d M');

It should be:

the_date('d M');

2) If you have some posts posted on the same date, the_date() will show only the date value for the 1st post. There will be no result for remained posts.

To get date of all post, use get_the_date() (which returns date value) or the_time() instead.

0

There is a explanation at top in the_date function reference. I try to use always the_time() instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.