WordPress.org

Ready to get started?Download WordPress

Forums

Need help. "About the Author" box at end of posts (7 posts)

  1. Travis Pflanz
    Member
    Posted 2 years ago #

    Let me start by saying, I am by no means a php pro.

    I would like to add author meta fields to the "About the Author" box following the post (http://cheifscommand.com).

    I know how to add the meta data, but I want to check to see if the author meta is present before displaying it as a link.

    Any help would be appreciated.

    Thanks.

  2. vtxyzzy
    Member
    Posted 2 years ago #

    Assuming that you retrieve the value like this:

    <?php $meta_value = get_post_meta($post->ID, 'my_meta_key', true); ?>

    You can test the value like this:

    <?php if ($meta_value) {
        // Do what you want with the value here
    } ?>
  3. Travis Pflanz
    Member
    Posted 2 years ago #

    Dang... Just noticed I have a typo in the URL... What a fool!
    http://chiefscommand.com

    vtxyxxy - Thanks for the reply. I suppose that is my question... How do I call the fields, check if they have a value, then display them as links (for Twitter, Facebook, Google+? I have some custom fields set up in the functions.php, as well as using some of the default the fields:

    display_name
    user_url
    twitter
    facebook
    googleplus
    description

    Thanks for the help

  4. vtxyzzy
    Member
    Posted 2 years ago #

    That seems too involved for an answer in this forum. You probably need to hire someone to program that for you.

  5. Travis Pflanz
    Member
    Posted 2 years ago #

    So, there's no way simple way to call author meta data on a post? There are already template tags built in for some of them, but others are more difficult, is this correct?

  6. vtxyzzy
    Member
    Posted 2 years ago #

    Well, I guess it depends on what you call simple. I showed above how to get Custom Field data and test for it. The author data can be retrieved with similar code. See the Codex here:

    http://codex.wordpress.org/Function_Reference/the_author_meta

    I do not understand what you mean by saying 'I have some custom fields set up in the functions.php', so I can't address how complicated using that would be.

    In general, you will need to do some coding for each field. Each field may also require some special formatting. That just seems to me to be a lot of work.

  7. Travis Pflanz
    Member
    Posted 2 years ago #

    This is what I have added to the functions.php to add Twitter, Facebook and Google+ to the user profile. I have also removed Yahoo Messenger, AOL Instant Messenger and Jabber

    // Contact Info fields in profile
    add_filter('user_contactmethods','new_contactmethods',10,1);
    function new_contactmethods( $contactmethods ) {
       $contactmethods['twitter'] = 'Twitter'; // Add Twitter
       $contactmethods['facebook'] = 'Facebook'; // Add Facebook
       $contactmethods['googleplus'] = 'Google+'; // Add Google+
       unset($contactmethods['yim']); // Remove YIM
       unset($contactmethods['aim']); // Remove AIM
       unset($contactmethods['jabber']); // Remove Jabber
    
       return $contactmethods;
    }

    Not all authors have each of these types of profiles. I want to display links to their social profiles, but only if they have entered their username in their profile for the social profile type. If they do not have a Twitter account (for example) I do not want anything displayed.

Topic Closed

This topic has been closed to new replies.

About this Topic