• I run a picture food blog (https://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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter chrisdkk

    (@chrisdkk)

    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.

    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; ?>

    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.

    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 ??

    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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Include author’s country of origin?’ is closed to new replies.