我需要为客户制作一个 WordPress 模板,他们在其中定义多个嵌套(2 级)页面并将它们显示在单个页面上。嵌套页面将位于选项卡部分中,因此用户可以通过更改选项卡在这些部分之间导航。他们还希望有几个页面正常显示(在单独的页面上)。为了处理这个问题,我想我可以对一个页面中的页面或单独的页面使用不同的模板。
我想出了如何显示页面,但我不知道如何让 WordPress 生成我想要的链接。如果可能的话,我想使用内置的 WordPress 菜单来构建带有锚点链接的菜单(就像<a href="#section">我不记得术语一样)。
除了付费主题外,我无法在 WordPress 中找到任何单页布局的示例(而且我付费不仅仅是为了看看其他人是如何做到的)。如果可能的话,我希望使用 WordPress 内置菜单,但如果没有,我想我可以自己构建菜单。
这是我显示页面的方式:
<?php
/**
 * Template Name: One Page Template
 */
get_header(); ?>
    <div id="primary">
        <div id="content" role="main">
            <?php query_posts(array(
                'post_type' => 'page',
                'post_parent' => 0,
                'orderby' => 'menu_order',
                'order' => 'ASC'
                // would also like to check something like 'template' => 'one-page'
            )); ?>
            <?php while (have_posts()) : the_post(); ?>
                <article class="page" id="<?php echo $post->post_name; ?>">
                    <h1><?php the_title(); ?></h1>
                    <?php the_content(); ?>
                    <?php $sub_pages = new WP_Query(array(
                        'post_type' => 'page',
                        'post_parent' => $post->ID,
                        'orderby' => 'menu_order',
                        'order' => 'ASC'
                    ));
                    while ($sub_pages->have_posts()) : $sub_pages->the_post(); ?>
                        <h2><?php the_title(); ?></h2>
                        <?php the_content(); ?>
                    <?php endwhile;?>
                </article>
            <?php endwhile; // end of the loop. ?>
        </div><!-- #content -->
    </div><!-- #primary -->
<?php get_footer(); ?>