首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加载页面内容时的困惑

问加载页面内容时的困惑
EN

WordPress Development用户
提问于 2012-08-25 17:02:16
回答 1查看 90关注 0票数 0

我正在将我的第一个完整的站点构建成WP,我对通过WP页面编辑器加载内容到实际页面所涉及的过程感到非常困惑。

例如,我有一个静态主页,我在主题文件的index.php中有这样的主页。

代码语言:javascript
复制
// Output header
get_header('home');

// Start Code that wraps the content

/***** Content of the page ******/

// End Code that wraps the content

get_sidebar();

get_footer();

现在,“页面内容”应该是用户通过WP Admin Pages菜单控制的代码/内容。

我怎么才能把这个写进这页?我读过你需要做这样的事。

代码语言:javascript
复制
if (have_posts()) {

    /* Start the Loop */

    while (have_posts()) {
        the_post();
        get_template_part('content');
    }

}

但是我很困惑,因为这再次使用了另一个内容页面(content.php)。为什么我需要创建另一个内容页面,而我所需要的只是页面内容区域的代码/数据?我不需要自己再加任何编码。

我稍微玩了一下,如果我这样称呼它,生成一个content.php文件并将<?php the_content(); ?>放入其中,内容就会显示出来。

仍然对这样做的目的感到困惑。

我假设您可以在许多事情中使用索引文件,然后在内容文件中放置特定的代码差异!?

为了帮助您更好地理解我的问题,我在下面的index.php文件中包含了确切的代码,并且我想知道我将如何将其划分为index.php和content.php?

代码语言:javascript
复制
<?php

// Output header
get_header('home');

?>

    <div id="main_holder">
        <div class="banner">
            <div id="slider">
                <div class="slide slide1">
                    <div class="title">
                        <p>We Navigate the</p>
                        <p>Maze for You</p>
                    </div>
                    <div class="text">
                        We provide a start-to-finish service in an area<br />
                        that can often be complex and confusing.
                    </div>
                    <div class="button button_big">
                        <a href="">Read more about<br /><span>registering a trademark</span></a>
                    </div>
                </div>
                <!-- Slide 1 Ends -->
            </div>
            <!-- Slider Ends -->
        </div>
        <!-- Banner Ends -->
        <div class="content">
            <div class="main">
                <div class="search_button">
                    <div class="left">
                        <h2><a href="<?php echo get_permalink(10); ?>">Free Trademark Search</a></h2>
                    </div>
                    <div class="right">
                        <a href="<?php echo get_permalink(10); ?>">Get Started Now!</a>
                    </div>
                </div>
                <!-- Search Button Ends -->

<?php

                if (have_posts()) {

                    /* Start the Loop */

                    while (have_posts()) {
                        the_post();
                        get_template_part( 'content', get_post_format() );
                    }

                } 

?>

            </div>
            <!-- Main Ends -->
             <?php get_sidebar(); ?> 
            <div class="contentClear"></div>
        </div>
        <!-- Content Ends -->
    </div>
    <!-- Main Holder Ends -->
    <div class="bottom"></div>

<?php

// Ouput footer
get_footer();

?>

非常感谢!

EN

回答 1

WordPress Development用户

发布于 2012-08-27 06:07:29

我不认为创建静态主页需要处理index.php或任何其他文件。您可以通过以下步骤创建一个静态主页:首先从wp发布页面,然后转到设置>>阅读>>首页显示>>静态页面>>从列表中选择页面。也就是说,如果您对主页有一些特殊的要求,并且需要编写自定义代码,那么您应该在主题中创建一个新文件为front-page.php。该文件的内容可以类似于:

代码语言:javascript
复制
<?php get_header(); ?>

<!-- all your custom code can go here -->

<?php get_sidebar();
<?php get_footer(); ?>
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/63045

复制
相关文章

相似问题

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