作者的详细信息,如社交媒体链接,电子邮件等→这是Meta还是其他什么?

时间:2017-05-10 作者:The WP Intermediate

我的第一篇文章的作者部分WordPress theme 当前为hard coded in HTML.

查看live网站here.

This One.

这些social media Icons 默认情况下,后端作者仪表板中不提供与它们关联的链接,需要对它们进行编码。enter image description here

有人能指导我怎么做吗?

此功能是否也属于元类别?

先生,我还有一个疑问,您编写的代码的哪一部分将用于打印我们保存在后端作者仪表板中的社交媒体URL。

为了简化我的查询,我把作者的代码放在这里显示在前端→

<div class="author-box">
    <div class="author-image">
        <img src="http://blog.blogeto.com/html/images/author_profile.png" alt="">
    </div>
    <div class="author-description">
        <h2>
            <!-- AUTHORS NAME --> <?php the_author(); ?>
            <!-- <a href="<?php get_author_posts_url(); ?>"><?php the_author() ?></a> -->
            <a href=""><i class="fa fa-home" aria-hidden="true"></i></a>
            <a href=""><i class="fa fa-home" aria-hidden="true"></i></a>
            <a href=""><i class="fa fa-facebook" aria-hidden="true"></i></a>
            <a href=""><i class="fa fa-twitter" aria-hidden="true"></i></a>
            <a href=""><i class="fa fa-linkedin" aria-hidden="true"></i></a>
            <a href=""><i class="fa fa-youtube" aria-hidden="true"></i></a>
        </h2>
        <p> Lorem Ipsum is simply dummy text.<a href="#">Read More</a> </p>
    </div>
    <div class="author-category">
      <ul>
          <li><a href="">CATEGORY 1</a></li>
          <li><a href="">CATEGORY 2</a></li>
          <li><a href="">CATEGORY 3</a></li>
          <li><a href="">CATEGORY 4</a></li>
          <li><a href="">CATEGORY 5</a></li>
      </ul>
    </div>
</div>

2 个回复
最合适的回答,由SO网友:Dave Romsey 整理而成

使用添加用户联系方式user_contactmethods 在主题中筛选functions.php 或通过插件:

用户联系方式条目存储在wp_usermeta 桌子URL字段是特殊的;它存储在user_url 中的字段wp_users 桌子

// Add user contact methods
add_filter( \'user_contactmethods\',\'wpse_user_contactmethods\', 10, 1 );
function wpse_user_contactmethods( $contact_methods ) {
    $contact_methods[\'facebook\'] = __( \'Facebook URL\', \'text_domain\'    );
    $contact_methods[\'twitter\']  = __( \'Twitter URL\', \'text_domain\' );
    $contact_methods[\'linkedin\'] = __( \'LinkedIn URL\', \'text_domain\'    );
    $contact_methods[\'youtube\']  = __( \'YouTube URL\', \'text_domain\' );

    return $contact_methods;
}
输出模板文件中的链接:

<div class="author-box">
    <div class="author-image">
        <img src="http://blog.blogeto.com/html/images/author_profile.png" alt="">
    </div>

    <div class="author-description">
        <h2>
        <!-- AUTHORS NAME --> <?php the_author(); ?>
        <!-- <a href="<?php echo get_author_posts_url( get_the_author_meta( \'ID\' ) ); ?>"><?php the_author() ?></a> -->
            <?php 
                // Get the id of the post\'s author.
                $author_id = get_the_author_meta( \'ID\' );

                // Get WP_User object for the author.
                $author_userdata = get_userdata( $author_id );

                // Get the author\'s website. It\'s stored in the wp_users table in the user_url field.
                $author_website = $author_userdata->data->user_url;

                // Get the rest of the author links. These are stored in the 
                // wp_usermeta table by the key assigned in wpse_user_contactmethods()
                $author_facebook = get_the_author_meta( \'facebook\', $author_id );
                $author_twitter  = get_the_author_meta( \'twitter\', $author_id  );
                $author_linkedin = get_the_author_meta( \'linkedin\', $author_id );
                $author_youtube  = get_the_author_meta( \'youtube\', $author_id  );

                // Output the user\'s social links if they have values.
                if ( $author_website ) {
                        printf( \'<a href="%s"><i class="fa fa-home" aria-hidden="true"></i></a>\',
                                esc_url( $author_website )
                        );
                }

                if ( $author_facebook ) {
                        printf( \'<a href="%s"><i class="fa fa-facebook" aria-hidden="true"></i></a>\',
                                esc_url( $author_facebook )
                        );
                }

                if ( $author_twitter ) {
                        printf( \'<a href="%s"><i class="fa fa-twitter" aria-hidden="true"></i></a>\',
                                esc_url( $author_twitter )
                        );
                }

                if ( $author_linkedin ) {
                        printf( \'<a href="%s"><i class="fa fa-linkedin" aria-hidden="true"></i></a>\',
                                esc_url( $author_linkedin )
                        );
                }

                if ( $author_youtube ) {
                        printf( \'<a href="%s"><i class="fa fa-youtube" aria-hidden="true"></i></a>\',
                                esc_url( $author_youtube )
                        );
                }
            ?>
        </h2>
        <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s.Lorem Ipsum is simply dummy text.   <a href="#">Read More</a> </p>
    </div>
    <div class="author-category">
        <ul>
                <li><a href="">CATEGORY 1</a></li>
                <li><a href="">CATEGORY 2</a></li>
                <li><a href="">CATEGORY 3</a></li>
                <li><a href="">CATEGORY 4</a></li>
                <li><a href="">CATEGORY 5</a></li>
        </ul>
    </div>
</div>

SO网友:Aniruddha Gawade

是的,这些字段将是用户元。为了存储用户的社交链接,您必须添加自定义用户元。

以下是供您参考的开发人员文档:https://developer.wordpress.org/plugins/users/working-with-user-metadata/

注意:请参阅示例代码以更好地理解。

结束