EDIT
Based on your last concern, here how I would do this.
The only problem left on your code is that you are calling some HTML inside PHP without `echo. So I split all those into seperates HTML tags and called them separatly in PHP.
<?php while(have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<figure class="thubmnail">
<?php the_post_thumbnail(get_the_ID(), 'medium'); ?>
</figure>
<p><?php the_excerpt(); ?></p>
<br/>
<a href="https://wordpress.stackexchange.com/questions/287577/<?php the_permalink(); ?>" class="button">Read more</a>
<hr/>
<?php endwhile; ?>
You should really look at the WordPress Codex to understand how and when using those functions as your question is not clear.
Link to the documentation : https://codex.wordpress.org/Class_Reference/WP_Query#Usage
In your PHP file or Template file, you should have something like this (loop) to be able to show the value of get_the_title()
and the_permalink()
or it will display the parent page values.
<?php
// the query
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<a href="https://wordpress.stackexchange.com/questions/287577/<?php the_permalink(); ?>">Read more</a>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
As for your second issue, the_title()
does not need to be in an <?php echo ... ?>
. The function will echo itself. https://codex.wordpress.org/Function_Reference/the_title
Displays or returns the unescaped title of the current post. This tag
may only be used within The Loop, to get the title of a post outside
of the loop use get_the_title. If the post is protected or private,
this will be noted by the words “Protected: ” or “Private: ” prepended
to the title
Hope it help you a little bit to clearly understand the concept.
If unclear, please update your question.