• Resolved jonathan1138

    (@jonathan1138)


    I would like to include the “file date”, as shown in the Downloadable Files/Versions section, in the output using a custom template, so that I end up with something like ’04/10/2020 – Document Title’. I see in the templates there are things like get_version() so I tried get_date and the_date but neither gave me the “file date”, only the 1st of the current month (or maybe it’s based on the folder the file exists in in WordPress, difficult to tell).

    Any clues please?

Viewing 6 replies - 1 through 6 (of 6 total)
  • if (date(“Hi”,$dlm_download->get_version()->get_date()->format( ‘U’ )) == ‘0000’)
    {
    echo date(“Y-m-d”,$dlm_download->get_version()->get_date()->format( ‘U’ ));
    }
    else
    {
    echo date(“Y-m-d H:i”,$dlm_download->get_version()->get_date()->format( ‘U’ ));
    }

    Thread Starter jonathan1138

    (@jonathan1138)

    Thank you for your reply f2065, however I can’t get that code to work. While attempting to debug, I noted that the first echo outputs nothing, the second echo throws an error.

    I have been scouring the documentation but can find no mention of
    get_version()->get_date()
    or any other method to get the date, only shortcode filters which is not useful to me I think.

    • This reply was modified 4 years, 1 month ago by jonathan1138.

    The first echo works if the time is 00:00 – so as not to display it.
    This was not the complete code, it is only part of the template.
    You need something like this template:

    <?php
    if ( ! defined( 'ABSPATH' ) ) {	exit; }
    ?>
    <p><a class="aligncenter download-button" href="<?php $dlm_download->the_download_link(); ?>" rel="nofollow">
    <?php 
    echo date("Y-m-d",$dlm_download->get_version()->get_date()->format( 'U' ));
    echo ' &ndash; ';
    printf( esc_html__( 'Download &ldquo;%s&rdquo;', 'download-monitor' ), $dlm_download->get_version()->get_filename() ); 
    ?>
    </a></p>
    Thread Starter jonathan1138

    (@jonathan1138)

    I used one of the existing templates for my code, I’ve just been struggling with the date part. Here is my code:

    <?php
    /**
     * Shows date and title only.
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    } // Exit if accessed directly
    
    ?>
    <?php 
    
    echo date(“Y-m-d”,$dlm_download->get_version()->get_date()->format( ‘U’ ));
    
    ?><a class="download-link" title="<?php if ( $dlm_download->get_version()->has_version_number() ) {
    	printf( esc_html__( 'Version %s', 'download-monitor' ), esc_html( $dlm_download->get_version()->get_version_number() ) );
    } ?>" href="<?php esc_url( $dlm_download->the_download_link() ); ?>" rel="nofollow">
    	<?php $dlm_download->the_title(); ?>
    </a>

    I expect the date to be printed and then the filename (it will look prettier once I get the date part working). I don’t need a button, just a text link over the document name, that part is working fine. Using this template outputs nothing where the date should be, I have confirmed that this is the template in use by adding other echo parts after the date echo line.

    • This reply was modified 4 years, 1 month ago by jonathan1138.

    Your code doesn’t work because your editor has corrupted the quotes.

    <?php
    /**
     * Shows date and title only.
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    } // Exit if accessed directly
    
    ?>
    <a class="download-link" title="<?php if ( $dlm_download->get_version()->has_version_number() ) {
    	printf( esc_html__( 'Version %s', 'download-monitor' ), esc_html( $dlm_download->get_version()->get_version_number() ) );
    } ?>" href="<?php esc_url( $dlm_download->the_download_link() ); ?>" rel="nofollow">
    	<?php echo date("Y-m-d",$dlm_download->get_version()->get_date()->format( 'U' ));
    	echo ' &ndash; ';
    	$dlm_download->the_title(); ?>
    </a>
    Thread Starter jonathan1138

    (@jonathan1138)

    Ah, I did spot that but thought I had replaced the quotes, evidently I missed some. Btw those were copied directly from here so I blame this website for quote misrepresentation! 😀

    Thanks, it’s working now.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom template to include file date’ is closed to new replies.