• Resolved Roman Neverov

    (@roman_neverov)


    I used to use $dlm_download->get_the_file_date(); in my template to get date and time of file.
    But it leads to fatal error in latest version of Download monitor.
    Please, tell me correct code to get date and timestamp of file.
    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Roman Neverov

    (@roman_neverov)

    I want to get
    Download title [size, format, timestamp]

    Here is my template

    <?php
    /**
     * Shows filetype, title, filesize and date.
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    } // Exit if accessed directly
    
    /** @var DLM_Download $dlm_download */
    ?>
    <a class="download-link filetype-icon <?php echo 'filetype-' . $dlm_download->get_version()->get_filetype(); ?>"
    title="<?php $dlm_download->the_title(); ?>" href="<?php $dlm_download->the_download_link(); ?>" rel="nofollow">
    	<?php $dlm_download->the_title(); ?></a> <text style="font-size : 70%;"><?php echo '[' ?><?php $dlm_download->get_version()->get_filesize_formatted(); ?><?php echo ',' ?> <?php $dlm_download->get_version()->get_filetype(); ?><?php echo ',' ?> <?php $dlm_download->get_version()->get_date(); ?><?php echo ']' ?> </text><br>

    As result I got empty fields (except title).
    Please, help me to fix code.

    • This reply was modified 6 years, 8 months ago by Roman Neverov.
    Thread Starter Roman Neverov

    (@roman_neverov)

    Thread Starter Roman Neverov

    (@roman_neverov)

    Sorry for my mistake.
    I forget about echo
    I made some improvements, so now my template looks like

    <?php
    /**
     * Shows filetype, title, filesize and date.
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    } // Exit if accessed directly
    
    /** @var DLM_Download $dlm_download */
    ?>
    
    <a class="download-link filetype-icon <?php echo 'filetype-' . $dlm_download->get_version()->get_filetype(); ?>"
    title="<?php $dlm_download->the_title(); ?>" href="<?php $dlm_download->the_download_link(); ?>" rel="nofollow">
    	<?php $dlm_download->the_title(); ?></a> <text style="font-size : 70%;"><?php echo '[' ?><?php echo $dlm_download->get_version()->get_filesize_formatted(); ?><?php echo ',' ?> <?php echo $dlm_download->get_version()->get_filetype(); ?><?php echo ',' ?> <?php get_option( 'date_format' ); echo $dlm_download->get_version()->get_date()->getTimestamp(); ?><?php echo ']' ?> </text><br>

    result – https://screenshots.firefox.com/wAY03mI6lJ9Z4No3/np-oros.ru
    and now its time to fix date format I think…

    • This reply was modified 6 years, 8 months ago by Roman Neverov.
    Thread Starter Roman Neverov

    (@roman_neverov)

    I made some improvements

    <?php
    /**
     * Shows filetype, title, filesize and date.
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    } // Exit if accessed directly
    
    /** @var DLM_Download $dlm_download */
    ?>
    
    <a class="download-link filetype-icon <?php echo 'filetype-' . $dlm_download->get_version()->get_filetype(); ?>"
    title="<?php $dlm_download->the_title(); ?>" href="<?php $dlm_download->the_download_link(); ?>" rel="nofollow">
    	<?php $dlm_download->the_title(); ?></a> <text style="font-size : 70%;"><?php echo '[' ?><?php echo $dlm_download->get_version()->get_filesize_formatted(); ?><?php echo ',' ?> <?php echo $dlm_download->get_version()->get_filetype(); ?><?php echo ',' ?> <?php get_option( 'date_format' ); echo $dlm_download->get_version()->get_date()->getTimestamp(); ?><?php echo ']' ?> </text><br>

    result – https://screenshots.firefox.com/wAY03mI6lJ9Z4No3/np-oros.ru
    and now its time to fix date format I think…

    Thread Starter Roman Neverov

    (@roman_neverov)

    My final result (it works!)

    <?php
    /**
     * Shows filetype, title, filesize and date.
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    } // Exit if accessed directly
    
    /** @var DLM_Download $dlm_download */
    ?>
    
    <a class="download-link filetype-icon <?php echo 'filetype-' . $dlm_download->get_version()->get_filetype(); ?>"
    title="<?php $dlm_download->the_title(); ?>" href="<?php $dlm_download->the_download_link(); ?>" rel="nofollow">
    	<?php $dlm_download->the_title(); ?></a> <text style="font-size : 70%;"><?php echo '[' ?><?php echo $dlm_download->get_version()->get_filetype(); ?><?php echo ', ' ?><?php echo $dlm_download->get_version()->get_filesize_formatted(); ?><?php echo ', ' ?><?php echo date_i18n( get_option( 'date_format' ), $dlm_download->get_version()->get_date()->getTimestamp() ); ?><?php echo ' D2 ' ?><?php echo date_i18n( get_option( 'time_format' ), $dlm_download->get_version()->get_date()->getTimestamp() ); ?><?php echo ']' ?> </text><br>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get filedate’ is closed to new replies.