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’ ));
}
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 ' – ';
printf( esc_html__( 'Download “%s”', 'download-monitor' ), $dlm_download->get_version()->get_filename() );
?>
</a></p>
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 ' – ';
$dlm_download->the_title(); ?>
</a>
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.