The MU forums have moved to WordPress.org

author age (1 post)

  1. kmaz
    Member
    Posted 15 years ago #

    This tips suppose that you already installed a plugin to add new fields in the user profile.
    So now let suppose (again) that you added the 3 fields for the birth date : month, day and year.
    So now if you want to display the age of the author resulting from this date in the author page :

    Paste after <?php get_header(); ?> in author.php :

    `<?php function birthday ($birthday) {
    list($year,$month,$day) = explode("-",$birthday);
    $year_diff = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff = date("d") - $day;
    if ($month_diff < 0) $year_diff--;
    elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
    return $year_diff;
    }
    ?>`

    And then where you want to display the age :

    Age : <?php echo birthday("$curauth->birth_year;-$curauth->birth_month;-$curauth->birth_day;");?>

    (N.B : birth_year, birth_month, birth_day) are the name of the usermeta and fields in your user profile)

About this Topic

  • Started 15 years ago by kmaz