Behseini
Behseini

Reputation: 6320

Custom Page Template Not Loading anything to Page

Using WordPress 3.7.1 I am not able to load and render anything on my Custom Page Template. I have a Custome Page Template as regPage.php and it has been coded as:

<?php
/*
Template Name: Regular Page
*/

 <?php get_header(); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php endwhile; ?>
    <?php the_content( ); ?>
    <?php else : ?>
    <h2>Page Not Found</h2>
    <?php endif; ?>
  <?php get_footer(); 
?>

While the Regular Page template is available on Page Attribute options I generate and publish the page (Lets' say Test) but when I check the Page(Test) it only shows a while empty page not even loading the Head , Style and Scripts tags from the header.
Here is an example of what happening :Sample Link
I test the header.php and footer.php they work fine on default template options but not working with my custom page template!Can you please let me know why this is happening and how I can fix it?

Upvotes: 0

Views: 2692

Answers (1)

Popnoodles
Popnoodles

Reputation: 28409

Two things. First a syntax error. You're opening <?php while <?php is open so close it first or do neither. They must balance.

<?php
/*
Template Name: Regular Page
*/
?> 
<?php get_header(); ?>

or

<?php
/*
Template Name: Regular Page
*/
get_header(); ?>

Second problem is you're looping through posts but your call to output their contents is outside the loop.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content( ); ?>
<?php endwhile; ?>
...

Though I imagine the_post() would still be set to the last iteration. It's the syntax error that caused a white screen. Turn debugging on.

Upvotes: 2

Related Questions