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


Wordpress PHP How to make theme show Static front page code

我已经阅读了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(); ?>

我还有 2 页。 header.phpfooter.php.这些页面中的两个内容都显示,我已经检查了它们的 html(在开发人员工具中)以确保它们正确显示。

我已经使用www.myurl.com'wp-admin在我的Word Press中创建了一个页面。我为页面Home Page标题及其内容:

<img src="http://url.co.za/wp-content/uploads/2014/11/Innokin-Logo.jpg" alt="Innokin Logo" width="243" height="93" />
<img src="http://url.co.za/wp-content/uploads/2014/11/Kingscrown.jpg" alt="Kingscrown" width="225" height="225" />
<img src="http://url.co.za/wp-content/uploads/2014/11/Suicide-Bunny.jpg" alt="Suicide Bunny" width="194" height="259" />
<img src="http://url.co.za/wp-content/uploads/2014/11/Kangertech.jpg" alt="Kangertech" width="128" height="128" />

首页只需要显示这 4 张图片。然后在我的主题设置中,我将"静态首页"设置为"静态页面",并将下拉列表中的页面设置为 Home Page

但是当我加载网站 URL 时,它看起来像进入无限循环,然后显示一条消息:Fatal error: Maximum execution time of 30 seconds exceeded in /home/vapekuet/public_html/wp-includes/formatting.php on line 527 . formatting.php不是我创建的PHP页面,所以我假设我的循环有问题。

谁能告诉我如何使用文字新闻和PHP显示当前页面内容。我不需要显示任何其他页面的任何信息,只需要显示当前页面的当前内容。IE:主页。

我还检查了Home Page是否设置为Admin -> Settings -> Reading

好的,正如我在问题中提到的,我观看了 youtube 视频,并在视频中我们创建了page.php文件。 Page.php似乎是需要显示内容的实际页面模板。感谢Bhumi Shah的答案和文字新闻页面。一旦我将循环从index.php复制到page.php,它就起作用

代码没问题。该错误可能是由于获取图像或互联网连接所花费的执行时间造成的。希望一段时间后会没事的。

问题是你没有创建一个头文件.php文件,但你已经包含了函数 get_header(),需要该文件。

您有两个选项:在索引上包含标头.php或创建 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(); ?>>