Display the "Read more" only in some posts

Hi
I’m using this code on content-extensions.php to display full content of some posts in home. It works on Travelify!

<?php
global $post;
if($post->post_excerpt){
the_excerpt();
}else{
the_content();
}

Now I would like to display the “Read more” button only in posts that use the_excerpt in home.

I found a tip in the codex https://codex.wordpress.org/Customizing_the_Read_More called “More about $more” that can be useful to display the “Read more” for only the first post. But I don’t know how to integrate it on my content-extensions.php. The code is:

<?php global $more; $more = -1; //declare and set $more before The Loop ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); //begin The Loop ?>
<?php
if ($more == -1) { //do not use the more tag on the first one.
the_content();
$more = 0; //prevent this from happening again. use the more tag from now on.
}
else { //use the more tag
the_content(__(‘Read more…’));
}
?>
<?php endwhile; //end of The Loop ?>

Please I need help to display the “Read more” only in posts that use the_excerpt, or since the third post onwards.

Hi @ianakarina,

I hope you are well today and thank you for your question.

Just try changing your above shared code as following.

<?php
global $post;
if($post->post_excerpt){
the_excerpt();
echo '<a class="readmore" href="' . get_permalink() . '" title="'.the_title( '', '', false ).'">'.__( 'Read more', 'travelify' ).'</a>';
}else{
the_content();
}

Best Regards,
Movin

Thanks Movin, but your code doesn´t work.
I already gave up, don´t worry.

It is working fine on my test site. Not sure how you are using it.

Please advise if you want any further help.

Have a fantastic day!