WordPress.org

Ready to get started?Download WordPress

Forums

adding the date to a wp_get_archives list (4 posts)

  1. buskerdog
    Member
    Posted 7 years ago #

    I'm using <?php wp_get_archives('type=postbypost&format=html'); ?> to list the titles of my posts. But I'd like the format to be: "Title (Date of post)"

    Is there any way to get it to include something like "(<?php the_time('F jS, Y') ?>)" after the post title?

  2. buskerdog
    Member
    Posted 7 years ago #

    Does anyone know how to do this?

  3. Pravin Paratey
    Member
    Posted 7 years ago #

    I'm also looking for something like this. Anybody?

  4. buskerdog
    Member
    Posted 7 years ago #

    This was not a full fix but I at least was able to format the date in a slightly more pleasing way by truncating the time off it:

    in wp-includes folder find templates-functions-general.php and loook for the
    } elseif ( 'postbypost' == $type ) { section which formates that post by post archives results.

    This is what I changed it to (I don't remember how much of it I changed so compare to your file:

    =====START OF CODE=====

    } elseif ( 'postbypost' == $type ) {

    $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);

    if ( $arcresults ) {
    foreach ( $arcresults as $arcresult ) {
    if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {

    $shortdate = $arcresult->post_date;
    $dateresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', DAYOFMONTH(post_date) AS 'dayofmonth' FROM $wpdb->posts WHERE post_date = '$shortdate'" . $limit);

    $date = sprintf("%02d-%02d-%d", $dateresults->month, $dateresults->dayofmonth, $dateresults->year);

    $url = get_permalink($arcresult);
    $arc_title = $arcresult->post_title;
    if ( $arc_title )
    $text = strip_tags($arc_title, $date);
    else
    $text = $arcresult->post_title . "title";
    echo get_archives_link($url, $text . " (" . substr($shortdate, 0, -9) . ")", $format, $before, $after);

    ====END OF CODE====

    The most important part is the substr($shortdate, 0, -9) near the end since that shaves the last 9 digits off the results getting rid of the time. Now my archives look like this: http://tinyurl.com/ze6xd which is not what I wanted but is acceptable.

Topic Closed

This topic has been closed to new replies.

About this Topic