Sorry I'm newbie with Wordpress, How to display 10 users only and the others inside "see more".
I searched more times before asking but with nothing!
Thanks in advance.
<?php
$post_id = get_the_ID();
$users_liked = get_post_meta( $post_id, '_user_liked', true );
if ( '' !== $users_liked && ! empty( $users_liked ) ) {
?>
<span>Liked:</span></br>
<?php foreach ( array_values( $users_liked ) as $user_id ) :
$user = get_user_by( 'id', $user_id );
if ( false === $user ) {
continue;
}
?>
<div class="sort-list-name">
<a href="<?php echo get_author_posts_url($user->ID);?>">
<?php echo get_avatar( $user->ID, 35 ); ?>
</a>
</div>
<?php
endforeach; ?>
<?php } ?>
first off all try to add an index in your loop
<?php
$post_id = get_the_ID();
$i = 0;
$users_liked = get_post_meta( $post_id, '_user_liked', true );
if ( '' !== $users_liked && ! empty( $users_liked ) ) {
?>
<span>Liked:</span></br>
<?php foreach ( array_values( $users_liked ) as $user_id ) :
$user = get_user_by( 'id', $user_id );
if ( false === $user ) {
continue;
}
?>
<div class="sort-list-name">
<a href="<?php echo get_author_posts_url($user->ID);?>">
<?php echo get_avatar( $user->ID, 35 ); ?>
</a>
</div>
<?php
if ($i++ == 9){
echo "<a href='#'>see more</a>";
break;
}
endforeach; ?>
<?php } ?>
and then if $i get 9 the loop will be break