php - 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 中,我在管理菜单中禁用了帖子,并为页面启用了分类。
请纠正我做错的地方。
解决方案
实际上从另一个主题复制代码 -
主要原因 - 页面未呈现是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
页面
推荐阅读
- python - 在python中组合两个图,但图不显示
- selenium - 除了 Galen 框架之外,是否有任何框架可以自动化网站的 UI
- ios - 将从 Fabric 创建的自定义事件迁移到 Firebase?
- java - 将 GLJPanel 作为 GUI 组件添加到 Intellij IDEA
- audio - 附加电影 MP4 列表会导致声音在某些时候丢失或出现乱码
- android - 如何在 Android 版本 10 即 Android Q 中禁用编辑文本的自动建议?
- laravel - 使用 \PDO::ATTR_EMULATE_PREPARES => true 时出现 Laravel 数据不匹配错误
- ios - UITableView reloadData() 导致在每个部分内重新加载到 UISearchBar
- python - 用 Python 中最接近的非 NaN 列值填充 NaN
- react-native - 带有 onEndReached 的 FlatList ScrollToIndex