douzhangwei5265 2016-01-06 13:47
浏览 44

wordpress不在the_content()或footer.php中加载

I am creating a custom theme, but have run into some problems. For your information my files are as seen below:

themes/
    aq-aquatics/
       css/
       img/
       js/
       footer.php
       functions.php
       header.php
       index.php
       page-homepage.php
       page-wide.php
       style.css
    index.php

This is my header.php

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="<?= get_template_directory_uri(); ?>/css/bootstrap.min.css">
<link href='https://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
<link href="http://fonts.googleapis.com/css?family=Arvo:400,700,400italic,700italic" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"  />
<meta name="author" content="Matthew Smart">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<![endif]-->
<title><?php wp_title(); ?></title>

<?php wp_head(); ?>

</head>
<body>
<div class="wrap">
<header>
    <div class="header-top text-right">
        <div class="container">
            <span style="margin-right:40px;">Tel: 01922 418050</span><span>Email: sales@hollybush-garden.com</span>
        </div>
    </div>
    <div class="container">
        <div class="header-content" style="min-height:86px;">
            <div class="row">
                <div class="col-sm-1" style="position:absolute;top:11px;z-index:1000;">
                    <img src="<?= get_template_directory_uri(); ?>/img/logo.png" width="108" height="100" alt="a&d logo"/>
                </div>
                <div class="col-sm-offset-1 col-sm-10 text-right" style="margin-left:132px;">
                    <nav class="navbar">
                        <div class="container">
                            <div>
                                <ul class="nav navbar-nav" style="width:inherit; border-bottom:none !important;margin-top:31px;">
                                    <li class="active"><a href="#">Home</a></li>
                                    <li class="dropdown">
                                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">At A & D
                                            <span class="caret"></span></a>
                                        <ul class="dropdown-menu">
                                            <li><a href="#">Page 1-1</a></li>
                                            <li><a href="#">Page 1-2</a></li>
                                            <li><a href="#">Page 1-3</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown">
                                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">Aquatics
                                            <span class="caret"></span></a>
                                        <ul class="dropdown-menu">
                                            <li><a href="#">Tropical</a></li>
                                            <li><a href="#">Pond</a></li>
                                            <li><a href="#">Marine</a></li>
                                            <li><a href="#">Cold water</a></li>
                                            <li><a href="#">Aquatics Sundries</a></li>
                                        </ul>
                                    </li>
                                    <li><a href="#">Valencia Wharf Coffee Shop</a></li>
                                    <li><a href="#">Opening Times</a></li>
                                    <li><a href="#">Contact Us</a></li>
                                </ul>
                            </div>
                        </div>
                    </nav>
                </div>
            </div>
        </div>
    </div>
    <div class="purple-line" style="margin-bottom:25px;"></div>
</header>

This is my page.wide.php

<?php
/*
Template Name: Wide Page
*/
get_header();

?>


<?php
if ( have_posts() ) {
    while ( have_posts() ) {
        //
        // Post Content here
        the_content();
        //
    } // end while
} // end if
?>


<?php get_footer(); ?>

And this is my footer.php

<footer>
<div class="container">
    <div class="col-sm-6">
        A&D AQUATIC & GARDEN CENTRE | WEBSITE DESIGN BY <span>MATTHEW SMART</span>
    </div>
    <div class="col-sm-6 text-right">
        <ul>
            <li>TERMS AND CONDITIONS</li>
            <li>PRIVACY POLICY</li>
            <li>COOKES</li>
        </ul>
    </div>
</div>

</footer>


</div><!-- End WRAP -->
<?php wp_footer(); ?>
</body>
</html>

Now the page i am trying to test is using the wide template. I have put some dummy text into the editor and clicked publish.

Now when i try to visit the page the first thing i can see is part of the header. The browser then takes another 5 seconds and loads the navigation which is in my header.php file.

It seems to just ignore everything from the page template and afterwards. So the_content() pulls nothing through and the footer doesn't get displayed.

I have been comparing these files with other themes i have created and cannot seem to find a cause.

Does anyone know why this may be happening?

Thanks

  • 写回答

1条回答 默认 最新

  • douyi8760 2016-01-06 13:53
    关注

    Your loop is missing the_post().

    <?php
    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post();
            //
            // Post Content here
            the_content();
            //
        } // end while
    } // end if
    ?>
    

    https://codex.wordpress.org/Function_Reference/the_post

    This is necessary to let WordPress know you are inside the loop, and retrieve the requested post's data. The footer isn't loading because the page is erroring out when it calls the_content() and cannot deal with this function outside the loop.

    According to WordPress documentation the_content "must be within The_Loop."

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记