【问题标题】:Scratch wordpress theme is not showing page content for page.phpScratch wordpress 主题不显示 page.php 的页面内容
【发布时间】:2020-07-15 06:33:39
【问题描述】:

我正在从头开始制作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中,我禁用了管理菜单中的帖子,并为页面启用了分类。

请纠正我做错的地方。

【问题讨论】:

    标签: php css wordpress wordpress-theming


    【解决方案1】:

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

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

    但是scratch主题在WebPagecontent-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 页面

    【讨论】:

      【解决方案2】:

      请尝试以下方法: 头:

      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
          <?php wp_head(); ?>
      </head>
      <body>
      

      功能: 使用您的默认主题功能二十二或更新

      page.php

      <div>
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
          <?php the_content(); ?>
          <?php endwhile; endif; ?>
      </div>
      <?php get_footer(); ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-24
        相关资源
        最近更新 更多