Я работаю над шорткодом, чтобы показать мой список авторов на WordPress; Мне удалось заставить работать поля социальных сетей, но я не могу их скрыть, если поле пустое.
Я думаю, мне нужно утверждение if
, но я не могу найти способ заставить его работать.
Вот код, который я сейчас использую:
function pippin_list_authors() {
$authors = get_users(array(
'orderby' => 'display_name',
'count_totals' => false,
'who' => 'authors',
'id' => ''
)
);
$list = '';
if($authors) :
$list .= '<div class="author-list">';
foreach($authors as $author) :
$list .= '<table>';
$archive_url = get_author_posts_url($author->ID);
$list .= '<tr>' . get_avatar($author->user_email, 100);
$list .= '<br><br><a class="author-list-name" href="'. $archive_url . '" title="' . __('Vedi tutti i post ', 'pippin') . $author->display_name . '">' . $author->display_name . '</a><br>';
$list.= '<br><br><div class="author-social"><a href="' . get_user_meta( $author->ID, 'facebook', true). '"><i class="fa fa-facebook"><p style="font-size: 0; color: transparent;">'.A.'</p></i></a>';
$list .= '<a href="https://twitter.com/' . get_user_meta($author->ID, 'twitter', true). '"><i class="fa fa-twitter"><p style="font-size: 0; color: transparent;">'.A.'</p></i></a>';
$list .= '<p class="author-bio" style="max-height: 103px; overflow: hidden; ">' . get_user_meta($author->ID, 'description', true) . '</p>';
$list .= '<div class="author-archive" style="text-align: center;"><a href="'. $archive_url . '" title="' . __('Vedi tutti i post ', 'pippin') . $author->display_name . '">' . __('Vedi tutti i post', 'pippin') . '</a></div>';
$list .= '</tr></table>';
endforeach;
$list .= '</div>';
endif;
return $list;
}
add_shortcode('authors', 'pippin_list_authors');