Forums

Include author's country of origin? (8 posts)

  1. chrisdkk
    Member
    Posted 5 years ago #

    I run a picture food blog (http://foodbloggin.com) and I thought it would be a nice addition if I could show a little flag with the author's country of origin next to their post.

    Is there any easy way to do this?

    Edit: I can get this information on my own, I guess I just need a way to include an image next to each author's name in each post.

  2. maerk
    Member
    Posted 5 years ago #

    You can use the custom meta fields underneath the post writing textbox. I don't remember the link on the codex, but there is definately something for meta. Hold on, I'll have a look.

  3. maerk
    Member
    Posted 5 years ago #

  4. chrisdkk
    Member
    Posted 5 years ago #

    Is it possible to limit access to this so only admins can change the information? I'd like to set everyone up and make sure it doesn't get changed.

  5. maerk
    Member
    Posted 5 years ago #

    Oh right, you can set that in the template file itself then:

    <?php if ( is_author(1) ) : ?>
    <!-- display flag for author 1 -->
    <?php elseif ( is_author(2) ) : ?>
    <!-- display flag for author 2 -->
    <?php elseif ( is_author(3) ) : ?>
    <!-- display flag for author 3 -->
    <?php elseif ( is_author(4) ) : ?>
    <!-- display flag for author 4 -->
    <?php else : ?>
    <!-- do some sort of default thing -->
    <?php endif; ?>

  6. maerk
    Member
    Posted 5 years ago #

    The number is the author ID, from Users > Authors & Users in WP admin.

    You can repeat as many of those

    <?php elseif ( is_author(3) ) : ?>
    <!-- display flag for author 3 -->

    As you need.

  7. maerk
    Member
    Posted 5 years ago #

    Oh wait, sorry, I'm lying :( that doesn't work as expected. You'll need to use a custom function. I'll look into it when I get home tonight, I need to look at the database to work on out, unless someone gets there before me :)

  8. maerk
    Member
    Posted 5 years ago #

    OK, put this in your functions.php file, if you have one.

    function is_by_author($test_id) {
    global $wpdb, $id;
    $actual_id = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE id = $id");
    if ( $actual_id == $test_id ) {
    return true;
    } else {
    return false;
    }
    }

    If you don't have one, create a blank text file, and put this into it:

    <?php function is_by_author($test_id) {
    global $wpdb, $id;
    $actual_id = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE id = $id");
    if ( $actual_id == $test_id ) {
    return true;
    } else {
    return false;
    }
    }
    ?>

    Now save this text file as functions.php and upload it to where all your other theme files are.

    Now you can use the code I gave you above, but instead of using is_author use is_by_author, so:

    <!-- display flag for author 1 -->
    <?php elseif ( is_by_author(2) ) : ?>
    <!-- display flag for author 2 -->
    <?php elseif ( is_by_author(3) ) : ?>
    ... etc

Topic Closed

This topic has been closed to new replies.

About this Topic