首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress -单独的页面作为首页的部分

问Wordpress -单独的页面作为首页的部分
EN

Stack Overflow用户
提问于 2015-05-15 23:57:59
回答 1查看 188关注 0票数 0

我创建了多个页面,比如服务、关于、我们的团队……在wordpress中,我和我可以修改这些页面的内容,为每个页面创建单独的php文件,比如page-services.php或page-about.php,这样我就可以在这些页面中使用高级自定义字段插件。但我现在需要做的是将这些页面作为部分包含在我的首页或静态页面中,因此以前的页面实际上是我的首页中的部分。我非常感谢任何人的帮助。

代码语言:javascript
复制
<div id="service" class="text-center">
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <h3><?php the_title(); ?></h3>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12">
            <p><?php the_field('service_subtitle'); ?></p>
        </div>
    </div>

    <div class="row">
        <?php if(get_field('service_box')): 

            while(has_sub_field('service_box')): ?>

            <div class="col-sm-4 column-box  wow fadeInUp  animated" data-wow-delay="0.3s">
                <h3><?php  echo the_sub_field('service_box_title'); ?></h3>
                <div class="title-line"></div>
                <p><?php  echo the_sub_field('service_box_content'); ?></p>
            </div>

        <?php   endwhile;

        else :

            // no rows found

        endif;

        ?>
    </div>
</div>

​

这是我在服务页面或page-service.php文件中的代码。现在我需要在我的首页中包含这个页面或代码。此外,我有多个这样的页面(部分),我需要包括在我的首页也。结束我不想只是复制这个和其他代码在首页,我不会让它在单独的页面,然后包括那些页面在首页。

EN

回答 1

Stack Overflow用户

发布于 2015-05-16 00:36:23

您可以根据ID查询页面内容,并插入到当前的首页代码中。就像下面的代码。

代码语言:javascript
复制
<?php
// Assume that the Id of the page you need to include is 7.
$mypages = get_pages( array( 'include' => '7', 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );

foreach( $mypages as $page ) {      
    $content = $page->post_content;
    if ( ! $content ) // Check for empty page
        continue;

    $content = apply_filters( 'the_content', $content );
?>
    <h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
    <div class="entry"><?php echo $content; ?></div>
<?php
}   
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30263875

复制
相关文章

相似问题

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