Some of my posts are translations from some other sources, and some are not. I need to add a new field after author's name. The field is "Translated by:" or "Translator:".
It should appear when there is a translator added to a post, and stay hidden when the post is not translated.
How can I add this new field to my posts and pages?
I used custom field to add "translator" to certain posts. Then I added this piece of code to the "single.php". The solution works fine on posts that have a translator:
Translated by: <?php echo get_post_meta($post->ID, 'translator',true); ?>
The problem is the words "Translated by:" show up on every post, instead of showing up only on the posts that have a "translator" custom field.
Any solution?
It would be simpler just to list the translator along with your other custom fields (if you have any) by placing the call <?php the_meta() ?> where you want it to appear. Then if your Key for the custom field is "Translated by:" and the Value is the translator's name, the credit will only appear on posts that have that custom field attached.
HTH.
I have several custom fields. How can it know it should show the value for the key "Traslator"?
Oh, you could just try something like:
<?php
$translator = get_post_meta($post->ID, 'translator', true);
if ( $translator ) {
echo "Translated by: $translator";
}
?>
Thank you. That works perfectly!