I am trying to understand how to use a custom template file, in this case simply to list all posts. Based on my research, and initial responses to this post, the code looks like this:
<?php
/**
* Template Name: Basic Test
*/
get_header();
if ( have_posts() ) :
while ( have_posts() ) : the_content();
the_title();
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
get_sidebar();
get_footer();
?>
When I create a new page that uses this template file, the page displays the header, footer, sidebar, page title, and nothing else. I assume I am missing something, but I don't know what. Neither posts nor the error message are displayed.
I am trying to understand how to use a custom template file, in this case simply to list all posts. Based on my research, and initial responses to this post, the code looks like this:
<?php
/**
* Template Name: Basic Test
*/
get_header();
if ( have_posts() ) :
while ( have_posts() ) : the_content();
the_title();
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
get_sidebar();
get_footer();
?>
When I create a new page that uses this template file, the page displays the header, footer, sidebar, page title, and nothing else. I assume I am missing something, but I don't know what. Neither posts nor the error message are displayed.
Share Improve this question edited Aug 1, 2020 at 13:23 Justin Freeman asked Jul 31, 2020 at 10:35 Justin FreemanJustin Freeman 11 bronze badge 3 |1 Answer
Reset to default -2I have seen that there is extra ();
so maybe this syntax error prevent display in front-end please try below code -
<?php
/**
* Template Name: Basic Test
*/
get_header();
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title();
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
get_sidebar();
get_footer();
?>
the_content();
. But like mozboz says, can you clarify what's not being displayed? – Tony Djukic Commented Jul 31, 2020 at 16:14