Your code should look like this to exclude duplicate titles
<ul>
<?php
// Initial counter for displayed posts.
$counter = 1;
// Initial empty array of displayed titles.
$titles = [];
$portfolio = new WP_Query([
'post_status' => 'publish',
'post_type' => 'post',
'cat' => '' . $link1 . '',
// Because we don't know the number of duplicate titles, fetch all.
'posts_per_page' => -1,
]);
if ( $portfolio->have_posts() ) :
// Start the loop.
while ( $portfolio->have_posts() ) : $portfolio->the_post();
// If the current title has not been displayed already, display it.
if ( ! in_array( get_the_title(), $titles ) ) {
?>
<li>
<a href="https://wordpress.stackexchange.com/questions/334890/<?php the_permalink(); ?>" target="_blank">
<?php the_title(); ?>
</a>
</li>
<?php
// Mark current title as displayed by adding it to the titles array.
$titles[] = get_the_title();
// Increase counter.
$counter++;
}
// When we have displayed 10 posts the loop should stop.
if ( $counter == 10 ) {
break;
}
endwhile; endif;
wp_reset_query(); ?>
</ul>
I hope this may help!