In my WordPress website, I want to show a short text of each blog_post on the custom blog template. I want to show a
Read More button with a link to the post at the end so a user can click on that link and view the full post.
But I am always getting the whole post instead of its summary.
Here is my code:
$moreLink = '<a href="' . the_permalink() . '"> Read More...</a>'; $wp_query = new WP_Query(); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="Read more"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php echo wp_trim_words( the_content(), 55, $moreLink); ?> <?php endwhile; ?>
I have tried different codes instead of
wp_trim_words(the_content(), 55, $moreLink); found online with no luck. Even I have used the same line of code on another custom template and it is working fine. However, with this template, it is not working.
Am I doing any mistake in my code?