【问题标题】:Get page content in custom template format获取自定义模板格式的页面内容
【发布时间】:2017-01-17 10:42:56
【问题描述】:

我尝试在 wordpress 中设置一个页面。我有一个带有自定义页面 tempate main.php 的主页。主页应该包含多个页面,因此我使用 WP 查询循环特定页面:

    $args = array(
    'post_type' => 'page',
    'order' => 'ASC',
    'post__in' => array(
        9,  //intro
        11, // about us
        15  // some other stuff
    ) 
);

$pagequery = new WP_Query( $args );

while ($pagequery->have_posts()) : $pagequery->the_post();

这在读出内容、标题和自定义字段方面没有任何缺陷。不幸的是,这三个页面都需要大量格式化,所以我也为这些页面设置了自定义模板(intro.php、about.php 等等......)。获取内容有效,但在定义的自定义模板中获取内容/页面在我看来是不可能的......

如何使页面完全格式化为自定义模板表单?还是我在这里做错了什么?

【问题讨论】:

    标签: php wordpress wordpress-theming custom-wordpress-pages


    【解决方案1】:

    为什么不只设置 1 页和 3 个部分?

    只创建一个模板并在主页上调用他。

    <?php /* Template Name: Main-page */ ?>
    
    <?php get_header(); ?>
    
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
    
            /* code here the 3 sections */
    
        </main><!-- .site-main -->
    
    </div><!-- .content-area -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    【讨论】:

    • 好吧,因为它们非常复杂且页面很大,所以会很乱......
    • 你仍然可以导入 3 个部分,这样可以减少混乱,这些部分将在不同的部分页面上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多