我创建了多个页面,比如服务、关于、我们的团队……在wordpress中,我和我可以修改这些页面的内容,为每个页面创建单独的php文件,比如page-services.php或page-about.php,这样我就可以在这些页面中使用高级自定义字段插件。但我现在需要做的是将这些页面作为部分包含在我的首页或静态页面中,因此以前的页面实际上是我的首页中的部分。我非常感谢任何人的帮助。
<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文件中的代码。现在我需要在我的首页中包含这个页面或代码。此外,我有多个这样的页面(部分),我需要包括在我的首页也。结束我不想只是复制这个和其他代码在首页,我不会让它在单独的页面,然后包括那些页面在首页。
发布于 2015-05-16 00:36:23
您可以根据ID查询页面内容,并插入到当前的首页代码中。就像下面的代码。
<?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
}
?>https://stackoverflow.com/questions/30263875
复制相似问题