Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a page with some text in it using this page-about.php as a template; page-about.php contains the basic:

<?php /* Template Name: About us */
get_header(); ?>
        <div id="primary">
            <div id="content" role="main">      

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

            </div><!-- #content -->
        </div><!-- #primary --> 

<?php get_footer(); ?>

What I don't really understand, if I create another page, let's say Coaching, assign page-coaching.php to it as a template, page-coaching.php having the same content as the one above but with /* Template Name: Coaching */, of course, when I view the page is showing me the content of the Homepage? And also Coaching disappeared from the menu?!

This is driving me crazy, any suggestions please?

I have created custom post types for both, exact copies, just changed about to coaching from one part to another, like this:

// Custom post type => ABOUT US
add_action( 'init', 'create_about' );
function create_about() {
  $labels = array(
    'name' => _x('About us', 'post type general name'),
    'singular_name' => _x('About us', 'post type singular name'),
    'add_new' => _x('Add New', 'About us'),
    'add_new_item' => __('Add New About us'),
    'edit_item' => __('Edit About us'),
    'new_item' => __('New About us'),
    'view_item' => __('View About us'),
    'search_items' => __('Search About us'),
    'not_found' =>  __('No About us found'),
    'not_found_in_trash' => __('No About us found in Trash'),
    'parent_item_colon' => ''
  );

  $supports = array('title', 'editor', 'revisions', 'excerpt', 'thumbnail', 'page-attributes');

  register_post_type( 'about',
    array(
      'labels' => $labels,
      'public' => true,
      'has_archive' => true,
      'hierarchical' => true,
      'query_var' => true,
      'supports' => $supports
    )
  );
}
share|improve this question
1  
why do you have a post type for about us? That doesn't make sense... –  m0r7if3r Feb 27 '12 at 16:29
    
As it will have several pages underneath which are going to be listed as a menu on the left side while in the About section, and I have chosen to use post types so I will have them nicely separated on the left side rather than having to simply create pages and assign then to a category. –  Chris Demetriad Feb 27 '12 at 16:40
1  
What about just using pages and subpages? Your code is ALL whacked up for what you're trying to do...so I'm trying to figure out what the best advice to give you is before I give it. –  m0r7if3r Feb 27 '12 at 16:42
    
Cristian that way of doing things is confusing and does not scale beyond a handful of pages. It also removes any sense of heirarchy and adds new problems for you to fix. If you need a sidemenu, just use a menu widget and sub pages –  Tom J Nowell Feb 27 '12 at 16:46
    
It appears that WordPress is doing exactly what you're telling it to do. Do you want to use static Pages, or do you want to use custom posts? You really can't mix-and-match the two. –  Chip Bennett Feb 27 '12 at 16:51
show 4 more comments

1 Answer

up vote 0 down vote accepted

You created a specific page template for a page called 'about' but your page is called 'About Us'. Try creating a page named 'About' or renaming your file to page-about-us.php.

Also use the cleaner formatting involving new lines:

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

You're also not checking if there is a post and executing the loop regardless

if( have_posts()){
    // put the while loop here
}

I have no idea why you have involved custom post types for this. You're working with a page template, and you assign page templates to pages. Those custom post type definitions may even be interfering with the working of your pages if they have the same post type name as your pages slug.

share|improve this answer
    
Renaming the page doesn't change a thing, as it can have any name as long as the chosen template is pointing to that page, am I wrong? I've done it anyway and this didn't change a thing. I have also reformatted the Template Name at the top without any changes. –  Chris Demetriad Feb 27 '12 at 17:00
    
Remove the custom post type code. Also page templates only work for pages. You cannot use a page template on a custom post type, you will need to use a different kind of template for that –  Tom J Nowell Feb 27 '12 at 17:06
    
Even if you refuse to remove the insanity that is the custom post type idea, at the very least, prefix the post types name with a common prefix –  Tom J Nowell Feb 27 '12 at 17:07
    
Hang on a second, the pages are created from Pages, not from the Custom post type menu. Like anyone would create a normal page, assign a template for it. And removing entirely the custom post types functions/code doesn't help either. –  Chris Demetriad Feb 27 '12 at 17:22
1  
Note, if you have a custom page template named page-about.php, and a static Page named "About", then WordPress will automagically use that page-about.php template file to render the "About" page. Refer to the Template Hierarchy. –  Chip Bennett Feb 27 '12 at 17:22
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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