页面上未显示作者社交媒体

时间:2019-11-26 作者:Ivanov

我试图在页面上显示作者的社交媒体,但根本没有显示。

这是我目前掌握的代码

$website = $user->user_url;
if($user->user_url != \'\') { 
   printf(\'<a href="%s">%s</a>\', $user->user_url, \'<i class="icon-home"></i>\'); 
}
$twitter = get_user_meta($user->ID, \'twitter_profile\', true);
if($twitter != \'\') {  
   printf(\'<a href="%s">%s</a>\', $twitter, \'<i class="icon-twitter"></i>\'); 
}
$facebook = get_user_meta($user->ID, \'facebook_profile\', true);
if($facebook != \'\') { 
   printf(\'<a href="%s">%s</a>\', $facebook, \'<i class="icon-facebook"></i>\');
}
$google = get_user_meta($user->ID, \'google_profile\', true);
if($google != \'\'){
   printf(\'<a href="%s">%s</a>\', $google, \'<i class="icon-google"></i>\');
}
$linkedin = get_user_meta($user->ID, \'linkedin_profile\', true);
if($linkedin != \'\'){ 
   printf(\'<a href="%s">%s</a>\', $linkedin, \'<i class="icon-linkedin"></i>\');
}
只有Website 可见。你知道哪里出了错吗?

1 个回复
SO网友:Firdaus Rudy

如果出现以下情况,请尝试此操作:

if(!empty($user->user_url)) { 
   // OUTPUT
}
所有代码


$website = $user->user_url;
if(!empty($user->user_url)) { 
   printf(\'<a href="%s">%s</a>\', $user->user_url, \'<i class="icon-home"></i>\'); 
}
$twitter = get_user_meta($user->ID, \'twitter_profile\', true);
if(!empty($twitter)) {  
   printf(\'<a href="%s">%s</a>\', $twitter, \'<i class="icon-twitter"></i>\'); 
}
$facebook = get_user_meta($user->ID, \'facebook_profile\', true);
if(!empty($facebook)) { 
   printf(\'<a href="%s">%s</a>\', $facebook, \'<i class="icon-facebook"></i>\');
}
$google = get_user_meta($user->ID, \'google_profile\', true);
if(!empty($google)){
   printf(\'<a href="%s">%s</a>\', $google, \'<i class="icon-google"></i>\');
}
$linkedin = get_user_meta($user->ID, \'linkedin_profile\', true);
if(!empty($linkedin)){ 
   printf(\'<a href="%s">%s</a>\', $linkedin, \'<i class="icon-linkedin"></i>\');
}
EDIT

Previously, you had to add code in the function according to your needs.

实例

<?php
//CREATE  CUSTOM USER DATA
add_action( \'show_user_profile\', \'facebook_custom_extra_profile_fields\' );
add_action( \'edit_user_profile\', \'facebook_custom_extra_profile_fields\' );

function facebook_custom_extra_profile_fields( $user ) { ?>

    <h3><?php echo esc_html__(\'Facebook URL\',\'text-domain\');?></h3>

    <table class="form-table">

        <tr>
            <th><label for="twitter"><?php echo esc_html__(\'Facebook URL\',\'text-domain\');?></label></th>

            <td>
                <input type="text" name="facebook_profile" id="facebook_profile" value="<?php echo esc_attr( get_the_author_meta( \'facebook_profile\', $user->ID ) ); ?>" class="regular-text" /><br />
                <span class="description"><?php echo esc_html__(\'Please enter Facebook URL.\',\'text-domain\');?></span>
            </td>
        </tr>

    </table>
<?php }


//SAVE CUSTOM USER DATA

add_action( \'personal_options_update\', \'facebook_custom_save_extra_profile_fields\' );
add_action( \'edit_user_profile_update\', \'facebook_custom_save_extra_profile_fields\' );

function facebook_custom_save_extra_profile_fields( $user_id ) {

    if ( !current_user_can( \'edit_user\', $user_id ) )
        return false;

    update_user_meta( $user_id, \'facebook_profile\', $_POST[\'facebook_profile\'] );
}

?>

相关推荐

Missing Author Information

我在单曲上显示作者姓名和头像时遇到问题。php页面。立柱装载良好,所有正确信息可用。然而,在哪里找不到头像和名字。我不确定我做错了什么。非常感谢您的帮助<div class=\"row\"> <div> <h1 class=\"primary-color\"> <?php the_title(); ?></h1> <span class=\"avatar\">