Forums

[resolved] A "Translated by" Field (7 posts)

  1. bluebird2
    Member
    Posted 3 years ago #

    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?

  2. bluebird2
    Member
    Posted 3 years ago #

    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?

  3. bluebird2
    Member
    Posted 3 years ago #

    Anybody here?

  4. bluebird2
    Member
    Posted 3 years ago #

    Anybody here?

  5. spoole
    Member
    Posted 3 years ago #

    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.

  6. bluebird2
    Member
    Posted 3 years ago #

    I have several custom fields. How can it know it should show the value for the key "Traslator"?

  7. spoole
    Member
    Posted 3 years ago #

    Oh, you could just try something like:

    <?php
    $translator = get_post_meta($post->ID, 'translator', true);
    if ( $translator ) {
    echo "Translated by: $translator";
    }
    ?>

  8. bluebird2
    Member
    Posted 3 years ago #

    Thank you. That works perfectly!

Topic Closed

This topic has been closed to new replies.

About this Topic