首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Wordpress如何加载模板文件和共享方法?

Wordpress如何加载模板文件和共享方法?
EN

Stack Overflow用户
提问于 2018-08-17 04:07:11
回答 1查看 9关注 0票数 0

使用Wordpress,你可以创建模板文件。我在查找它如何加载文件时遇到了一些困难。这是因为大多数框架将使用Ob、start等,但wordpress仍然可以访问返回对象的方法。例如:

代码语言:javascript
复制
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

        <?php
        // Start the loop.
        while ( have_posts() ) : the_post();

            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }

            // End of the loop.
        endwhile;
        ?>

    </main><!-- .site-main -->

    <?php get_sidebar( 'content-bottom' ); ?>

上面的代码片段使用了the_post()和get_side()等方法(或函数)。

Wordpress如何加载模板并提供上述函数的使用?

EN

回答 1

Stack Overflow用户

发布于 2018-08-17 07:48:46

您需要具有特定名称的文件:

代码语言:javascript
复制
template-your_name.php

并添加文件的第一部分:

代码语言:javascript
复制
<php
/*
Template Name: Your template name
*/

之后,您将在模板列表中看到它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51884587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档