簡體   English   中英

如何將wordpress網站的頁眉和頁腳包含到自定義php文件中?

[英]How to include the header and the footer of wordpress website to a custom php file?

我有一個自定義php文件,我想將header.php和footer.php文件包括到其中,該文件位於header.php和footer.php旁邊的主題文件中,但是當我嘗試時

<?php get_header(); ?>

我收到一個錯誤,未定義函數get_header。

有沒有一種方法可以包含它,或者我必須使用include / require手動包含它們?

您是否在項目中創建了這些文件? 您應該在項目上創建一個footer.phpheader.php

您的頁面應如下所示:

<!-- The header of the page -->
<?php get_header(); ?>
<!-- The main wrapper of the page -->
<main class="main-container container_960">
    <!-- Main content Section -->
    <section class="main-content">
        <!-- Printing the content -->
        <?php if (have_posts()) : while (have_posts()) :the_post() ?>

            <?php
                    the_title("<h1>","</h1>");

                    the_content();
            ?>

        <?php endwhile; else : ?>
            <!-- Showing that there is no content -->
            <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
        <?php endif; ?>

    </section>
    <!-- Pinting the Sidebar -->
    <?php get_sidebar(); ?>

</main>
<!-- Printing the footer -->
<?php get_footer() ?>

為標題創建一個文件,將其稱為header.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php  the_title();?></title>
    <!-- This is for adding the meta information, where styles registered in functions php --> 
    <?php wp_head(); ?>
</head>
<body>

<header class="the_header">
<!-- You can create your content here
</header>
...

同樣,您還應該為footer創建另一個文件footer.php

<footer class="main-footer">
        The footer
    </footer>

    <!-- We call here the scripts enqeued in functions.php-->
    <?php wp_footer();?>
</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM