[wp-trac] [WordPress Trac] #56762: PHP file being ignored in block theme hierarchy

WordPress Trac noreply at wordpress.org
Thu Oct 20 11:42:22 UTC 2022


#56762: PHP file being ignored in block theme hierarchy
---------------------------+------------------------------
 Reporter:  ryanpluckrose  |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Themes         |     Version:  6.0.2
 Severity:  major          |  Resolution:
 Keywords:  needs-patch    |     Focuses:  template
---------------------------+------------------------------

Comment (by ryanpluckrose):

 Yeah I'm currently working with page.php in the root to solve the issue, I
 didn't realise at the time it was by design.

 I had assumed that template-parts would fallback in the same way templates
 do as above but if that's by design then I guess it's not a bug.

 https://fullsiteediting.com/ has been very helpful for getting me this far
 though, so thank you!

 Because page.php is used I now get a white page using Appearance > Site
 Editor, I know that it's not supposed to work with PHP files but is that
 the intended result?

 How should the user edit the nav menu in this context, do I need to enable
 appearance > menus? I thought this method was now legacy.

 For reference, this is my use case:
 - On pages, users will have the option to select a STYLE dropdown, this
 will update the frontend based on the styles json files e.g.
 styles/swiss.json or styles/blue.json
 - If one of these is selected, as well as the styles, the menu will change
 so i needed an IF statement around the nav, this is where I hit trouble
 with PHP template parts as Will mentions above.

 I've currently changed my implementation so that header.html will not be
 used but instead I'll call a smaller nav.html and put the rest of the
 header inside a php file called from page.php

 {{{#!php
 <!doctype html>
 <html <?php language_attributes(); ?>>
     <head>
         <meta charset="<?php bloginfo( 'charset' ); ?>">
         <?php wp_head(); ?>
     </head>
     <body <?php body_class(); ?>>
         <?php wp_body_open(); ?>
         <div class="wp-site-blocks">
             <?php get_template_part( 'header' ) ?>
             <?php get_template_part( 'content' ) ?>
             <footer class="wp-block-template-part site-footer">
                 <?php block_footer_area(); ?>
             </footer>
         </div>
         <?php wp_footer(); ?>
     </body>
 </html>

 }}}


 snippet of my header.php (further down I'll call my nav.html part)

 {{{#!php
         <?php if ( isset( $meta_page_style ) && $meta_page_style !==
 'default' ): ?>
                 <?php // Alternative header when top nav is removed ?>
                 <?= $part_header_alt ?>
         <?php else: ?>
                 <?php block_header_area(); ?>
         <?php endif; ?>

     <div class="wp-block-group is-layout-constrained">
         <div class="is-content-justification-left is-nowrap is-layout-flex
 wp-block-group alignwide">
                         <?= do_blocks( '<!-- wp:site-logo
 {"width":218,"shouldSyncIcon":true,"className":"is-style-default"} /-->' )
 ?>
             <div class="wp-header-spacer"></div>

 }}}


 Thank you!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56762#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list