首页 > 解决方案 > Scratch wordpress 主题不显示 page.php 的页面内容

问题描述

我正在Wordpress从头开始制作主题。我page.php没有显示/加载Lorem页面内容

//page.php
  get_header(); ?>
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', 'page' ); ?>
                <?php if ( comments_open() || get_comments_number() ) : ?>
                    <?php comments_template(); ?>
                <?php endif; ?>
            <?php endwhile; ?>
        </main><!-- #main -->
    </div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_sidebar( 'tertiary' ); ?>
    <?php get_footer(); ?>

我有

   //header.php

    <!DOCTYPE html>
    <html>
    <head>
    <?php wp_head();?>
    </head>
    <body>
    <h1>Test Header</h1>

    </html>

其他

//functions.php      
<?php
    function remove_posts_menu() {
        remove_menu_page('edit.php');
    }
    add_action('admin_menu', 'remove_posts_menu');

    function add_taxonomies_to_pages() {
        // register_taxonomy_for_object_type( 'post_tag', 'page' );
        register_taxonomy_for_object_type( 'category', 'page' );
        }
       add_action( 'init', 'add_taxonomies_to_pages' );



    if ( ! is_admin() ) {
        add_action( 'pre_get_posts', 'category_and_tag_archives' );

        }
    function category_and_tag_archives( $wp_query ) {
       $my_post_array = array('post','page');

        if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
        $wp_query->set( 'post_type', $my_post_array );

        if ( $wp_query->get( 'tag' ) )
        $wp_query->set( 'post_type', $my_post_array );
       }

    function remove_page_attribute_support() {
        remove_post_type_support('page','page-attributes');
    }
    add_action( 'init', 'remove_page_attribute_support' );

在 functions.php 中,我在管理菜单中禁用了帖子,并为页面启用了分类。

请纠正我做错的地方。

标签: phpcsswordpresswordpress-theming

解决方案


实际上从另一个主题复制代码 -

主要原因 - 页面未呈现是page.php调用其他主题模板文件来显示内容。

但是临时主题没有内容文件夹,也没有用于在其中呈现内容的额外模板WebPage content-xx.php

//page.php   
 <?php   
    get_header(); ?>
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php the_content();?>
             <?php endwhile; ?>
        </main><!-- #main -->
    </div><!-- #primary -->
    <!-- <?php get_sidebar(); ?> -->

    <?php get_footer(); ?>

最终渲染了lorem-imsum页面


推荐阅读