0

I have a custom page template named "page-news.php" and it contains

<?php
/*
* Template Name: News
*/
get_header();

?>
test
<?php 
wp_footer();
get_footer();
?>

and I then create a page and set the template to "News" but when I view the page, it does not display the contents on the page-news.php custom page template, instead it display the archive.php contents (I have test it, whatever I put unto the archive.php contents, it display on the page that I hook unto the page-news.php custom page template). Any ideas, help please? I'm running WP 4.7.2.

3 Answers 3

0

Every thing is right except wp_footer().

Remove wp_footer(), rename your file name and check again.

2
  • what do you mean by renaming the file name? is it from page-news.php to page-whatever.php? Feb 8, 2017 at 7:27
  • I tried to change the permalinks settings to "plain" instead of "post name" and it works (the custom page template did display), any ideas how to make it work to "post name" permalinks instead of plain permalinks? Feb 8, 2017 at 7:38
0

The problem is with the page slug.There should be same slug of your custom post type and the slug of your page.

Try the same thing after changing the slug of page.Changing page slug will solve your problem.

1
  • I tried to change the permalinks settings to "plain" instead of "post name" and it works (the custom page template did display), any ideas how to make it work to "post name" permalinks instead of plain permalinks? Feb 8, 2017 at 7:38
0

Please follow the steps:

(1) Please rename your page-news.php file to say archive-news.php

(2) Please remove (/* Template Name:.... */) text from the top of your file as it is no useful anymore.


Notes:

(1) This will make your template your template to work as an archive file.

(2) You will no need to assign Template from the back end anymore.



If it does not work:

(1) Try updating your permalinks.

(2) Try setting your news page's slug as 'news'

Thank you.

4
  • I dont want to hook it as a archive things, I just want it to be a custom page template. Feb 8, 2017 at 7:35
  • I tried to change the permalinks settings to "plain" instead of "post name" and it works (the custom page template did display), any ideas how to make it work to "post name" permalinks instead of plain permalinks? Feb 8, 2017 at 7:38
  • You may have post type with the same slug (news). Then please make sure that your page has different slug than 'news'. Feb 8, 2017 at 7:38
  • try this permalinks: /%category%/%postname%/ Feb 8, 2017 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.