• I am working with a theme I have made myself. The theme has one custom post type and two custom taxonomies.

    The problem I have is that the page.php file is not being picked up for high-level pages. It works for child pages. But high-level pages are being displayed with index.php (I have no home.php page.)

    The site is set up to display a static front page using front-page.php, which works correctly. Blog archive is supposed to display using index.php, which also works correctly.

    But my 3 parent pages, which are linked in the “About Menu” in the footer of the page are all displaying incorrectly, using index.php instead of page.php. Child pages such as /about-mdd/interviews/ are displaying correctly using page.php.

    Possibly related: any URL like martindenton.com/xyz also displays the index page rather than the 404.php page. Incorrect category urls work correctly showing 404.php.

    Would appreciate any help, thanks!

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Well this should work as by default for pages it calls page.php of theme.
    Few things you can try to troubleshoot the issue is
    1) Disable all plugins and check if its picking page.php for the mentioned page.
    2) Try resetting permalinks from settings->permalinks.

    Also, can you paste the code here for page.php file ? I think that can be the issue.

    Thread Starter mddenton

    (@mddenton)

    Thanks for the reply! I have already done both of the two things you suggested, and neither has helped.

    Here is the code for page.php:

    <?php
    
    get_header();
    
    while(have_posts()) {
        the_post(); ?>
        
        <div class="page-banner">
        <div class="page-banner__bg-image" style="background-image: url(<?php echo get_theme_file_uri('/images/ocean.jpg'); ?>)"></div>
        <div class="page-banner__content container container--narrow">
          <h1 class="page-banner__title"><?php the_title(); ?></h1>
          
        </div>  
      </div>
    
      <div class="container container--narrow page-section">
    
        <?php
          $parentID = wp_get_post_parent_id(get_the_ID());
          if ($parentID) { ?>
    
          <div class="metabox metabox--position-up metabox--with-home-link">
            <p><a class="metabox__blog-home-link" href="<?php echo get_permalink($parentID); ?>"><i class="fa fa-home" aria-hidden="true"></i> Back to <?php echo get_the_title($parentID); ?></a> <span class="metabox__main"><?php the_title(); ?></span></p>
          </div>
    
        <?php  } ?>
        <?php
        $testArray =  get_pages(array('child_of'=>get_the_id()));
        if ($parentID or $testArray) {
        ?>
    
        <div class="page-links">
          <h2 class="page-links__title"><a href="<?php echo get_permalink($parentID); ?>"><?php echo get_the_title($parentID); ?></a></h2>
          <ul class="min-list">
            <?php
            if ($parentID) {
              $findChildrenOf = $parentID;
            }
            else{
              $findChildrenOf = get_the_ID();
            }
            wp_list_pages(array(
              'title_li'=> NULL,
              'child_of'=> $findChildrenOf 
            ));
            ?>
          </ul>
        </div>
      <?php }  ?>
        <div class="generic-content">
          <?php the_content(); ?>
        </div>
    
      </div>
    
    <?php }
    
    get_footer();
    
    ?>

    Note that this was working correctly until I installed the custom taxonomies. Could that have something to do with this?

    code in page.php seems to be ok. Did you use any plugin for custom taxonomies or written script in functions.php ?
    There can be something in your custom theme that’s breaking template hierarchy.

    Thread Starter mddenton

    (@mddenton)

    Thanks again. This is the script for custom-post-types.php in mu-plugins folder

    <?php
    
    function custom_post_types() {
        register_post_type('review', array(
            'show_in_rest' => true, // enables modern block-style editor display of this post type
            'supports' => array('title', 'editor', 'excerpt'),
            'rewrite' => array(
                'slug' => 'reviews',
            ),
            'has_archive' => true,
            'public' => true,
            'show_in_nav_menus' => true, 
            'labels' => array(
                'name' => 'Reviews',
                'add_new_item' => 'Add New Review',
                'edit_item' => 'Edit Review', 
                'all_items' => 'All Reviews',
                'singular_name' => 'Review',
                'new_item' => 'New Review',
                'view_item' => 'View Review',
                'search_items' => 'Search Reviews',
                'not_found' => 'No Reviews Found.'
            ),
            'menu_icon' => 'dashicons-thumbs-up',
            'description' => 'Reviews written by Martin Denton, 1997 - 2016'
        ));
    }
    
    // eventually add tag cloud functionality!
    function custom_taxonomies() {
        register_taxonomy('company', 'review', array(
            'labels' => array(
                'name'              => 'Company',
                'singular_name'     => 'Company',
                'search_items'      => 'Search Companies',
                'all_items'         => 'All Companies',
                'edit_item'         => 'Edit Company',
                'update_item'       => 'Update Company',
                'add_new_item'      => 'Add Company',
                'new_item_name'     => 'New Company',
                'menu_name'         => 'Companies',
            ),
            'show_in_rest' => true,
            'public' => true,
            'hierarchical'  => false,
            'show_ui'       => true, 
            'show_admin_column' => true, //add the taxonomies to the wordpress admin
            'query_var'         => true,
            'rewrite'       => array('slug' => 'company')
        ));
    
        register_taxonomy('year', 'review', array(
            'labels' => array(
                'name'              => 'Year',
                'singular_name'     => 'Year',
                'search_items'      => 'Search Years',
                'all_items'         => 'All Years',
                'edit_item'         => 'Edit Year',
                'update_item'       => 'Update Year',
                'add_new_item'      => 'Add Year',
                'new_item_name'     => 'New Year',
                'menu_name'         => 'Years',
            ),
            'show_in_rest' => true,
            'public' => true,
            'hierarchical'  => false,
            'show_ui'       => true, 
            'show_admin_column' => true, //add the taxonomies to the wordpress admin
            'query_var'         => true,
            'rewrite'       => array('slug' => 'year')
        ));
    }
    
    add_action('init', 'custom_post_types');
    add_action('init', 'custom_taxonomies');
    
    ?>

    I tried to change the taxonomy ‘year’ to ‘revyear’ and it still didn’t work.

    This also seems to be fine, I think untill & unless we don’t have access to the theme code, its impossible to debug what the issue is. Can you provide a zip file of theme you’re building ?

    Thread Starter mddenton

    (@mddenton)

    Thanks for the help. I have figured out the problem. I rebuilt my site today using a different name for my taxonomy. (I had used “year” which is a reserved word in WP. I now use “season” which is not reserved.)

    The result is that the site works perfectly now. So the use of the reserved word seems to have been the problem.

    Lesson learned!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘page.php not working for top-level pages’ is closed to new replies.