• Resolved garri83

    (@garri83)


    Подскажите как вывести количество дней, например: сайт работает Х дней? Дату в посте указываю через “Date (дата)”.

    
    use Carbon_Fields\Container;
    use Carbon_Fields\Field;
    
    Container::make('post_meta', 'Свойства')
    	->show_on_post_type('resources')
    	->add_fields(array(
    		Field::make("date", "crb_my_date", "Дата")
    
    

    Выводить надо в одиночной записи и в категории. В wp есть функция human_time_diff():

    $human_time = human_time_diff( get_post_time( 'U', true ) );
    echo "Сайт работает $human_time дней.";

    но как сделать не знаю 8(

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Atanas Angelov

    (@atanasangelovdev)

    Hello @garri83,

    Unfortunately, we only provide support in English – could you please post your message again in English?

    Thread Starter garri83

    (@garri83)

    I have created a field like this: Field :: make ('date', 'crb_start_site', 'Site start date')

    This is how to display this field in the front-end in an arihive and in a single post in the form “Site work X days”?

    Plugin Contributor Atanas Angelov

    (@atanasangelovdev)

    You can get the field value using this function:
    $date = carbon_get_the_post_meta( 'crb_start_site );

    Then you need to convert it using a library such as nesbot/carbon (http://carbon.nesbot.com/docs/#api-difference)

    Thread Starter garri83

    (@garri83)

    Thanks for the answer. I do not know much about PHP, and it’s hard for me to convert the date using the library without instructions. 8 (

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Отсчет Х дней’ is closed to new replies.