385 delte
Jeg har i mine Shaarli henvisninger til:
Elegant WordPress Solution for Dynamic Copyright Date
32 Extremely Useful Tricks for the WordPress Functions File
Været optaget af hvordan man kan anvende en funktion til at indsætte dynamisk ©️ information.
Med FSE benyttes ikke længere footer.php til footer information. Men der kan stadig benyttes php-script.
Indsæt funktionen i temaets functions.php :
/* ===========
-ckn- Her laver vi dynamisk copyrigt på vores side.
Indsæt for eksempel i footer.php et kald til funktionen.
<?php echo ckn_copyright(); ?>
========*/
function ckn_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = '';
if($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}
Herefter kan funktionen kaldes hvorsomhelst med :
<?php echo ckn_copyright(); ?>
For eksempel i sidefods template.