Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Insert a cc license by a custom field.
<?php
$cc_licenses = array(
'ccnc' => '<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/deed.de"><img alt="Creative Commons Lizenzvertrag" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/4.0/88x31.png" /></a><br />Dieses Werk ist lizenziert unter einer <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/deed.de">Creative Commons Namensnennung-Nicht kommerziell 4.0 International Lizenz</a>.',
'ccncsa' => '<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/deed.de"><img alt="Creative Commons Lizenzvertrag" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />Dieses Werk ist lizenziert unter einer <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/deed.de">Creative Commons Namensnennung - Nicht-kommerziell - Weitergabe unter gleichen Bedingungen 4.0 International Lizenz</a>.';
'ccncnd' => '<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de"><img alt="Creative Commons Lizenzvertrag" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br />Dieses Werk ist lizenziert unter einer <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de">Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz</a>.',
);
foreach ( $cc_licenses as $cc_license => $html ) {
// first try exact match...
$current_license = get_post_meta( $post->ID, $cc_license, true );
// ...then try lowercase letters...
if ( empty( $current_license ) )
$current_license = get_post_meta( $post->ID, strtolower( $cc_license ), true );
// ...finaly try uppercase letters.
if ( empty( $current_license ) )
$current_license = get_post_meta( $post->ID, strtoupper( $cc_license ), true );
if ( ! empty( $current_license ) ) {
echo $html;
break;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.