Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress PHP如何使主题显示静态首页代码_Php_Wordpress - Fatal编程技术网

Wordpress PHP如何使主题显示静态首页代码

Wordpress PHP如何使主题显示静态首页代码,php,wordpress,Php,Wordpress,我已经阅读了Word Press上的文档。我已经观看了创建word press主题,但似乎无法显示内容 在我的主题index.php文件中,我有以下代码: <?php get_header(); ?> <div> <?php // TO SHOW THE PAGE CONTENTS while ( have_posts() ) : the_post(); ?> <!--Because the_content() works on

我已经阅读了Word Press上的文档。我已经观看了创建word press主题,但似乎无法显示内容

在我的主题
index.php
文件中,我有以下代码:

<?php get_header(); ?>

<div>
    <?php
    // TO SHOW THE PAGE CONTENTS
    while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
            <?php the_content(); ?> <!-- Page Content -->
    <?php
    endwhile; //resetting the page loop
    wp_reset_query(); //resetting the page query
    ?>
</div>

<?php get_footer(); ?>
首页只需要显示这4张图片。然后在我的主题设置中,我将“静态首页”设置为“静态页面”,并将下拉列表中的页面设置为
主页

但当我加载网站URL时,它似乎进入无限循环,然后显示一条消息:
致命错误:第527行的/home/vapekuet/public_html/wp includes/formatting.php中超过了30秒的最长执行时间
formatting.php
不是我创建的php页面,因此我假设我的循环有问题

有人能告诉我如何使用word press和PHP显示当前页面内容吗。我不需要显示任何其他页面的任何信息,只需要显示当前页面的当前内容。IE:主页


我还检查了
主页
是否设置在
管理->设置->阅读
好的,正如我在问题中提到的,我观看了youtube视频,在视频中我们创建了
页面.php
文件
Page.php
似乎是需要显示内容的实际页面模板。感谢
普密沙阿
的回答和支持。当我将循环从
index.php
复制到
page.php

时,它就起作用了。问题是,您没有创建header.php文件,但包含了函数get_header(),它需要该文件

您有两个选项:在index.php或creatinga hader.php文件中包含标题

标题应如下所示:

<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width" />
<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;

wp_title( '|', true, 'right' );

// Add the blog name.
bloginfo( 'name' );

// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " | $site_description";

// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( 'Page %s', 'shape' ), max( $paged, $page ) );

?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->
<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>


代码正常。错误可能是由于获取图像或internet连接所需的执行时间。希望过一段时间就可以了。

您为主页创建了页面模板了吗?您所说的主页页面模板是什么意思?如果我在php中理解正确,您需要指定内容需要输出到哪里?我想在它读取index.php页面时输出它,所以页眉和页脚会显示出来,但在内容中它会显示错误?没关系,我让它工作了,你是对的,我需要将它添加到page.php中。你应该检查wordpress模板层次结构,了解它决定使用什么模板的更多信息。有一个很好的图表。FWIW,WordPress不需要page.php…但是如果你包含它,你需要包含一个循环。我有一个header.php文件,它还输出header.php文件中的内容。问题是页面模板
page.php
文件没有正确的循环。
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width" />
<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;

wp_title( '|', true, 'right' );

// Add the blog name.
bloginfo( 'name' );

// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " | $site_description";

// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( 'Page %s', 'shape' ), max( $paged, $page ) );

?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->
<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>