有人帮忙!我是Wordpress的新手,并尝试从头开始构建单页响应(引导程序)主题。我的index.php页面如下所示:
<?php get_header(); ?>
<section id="plx_mission_section" >
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><h2>title</h2></div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><p>text</p></div>
</div>
</div>
</section>
<section id="plx_whyus_section" >
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><h2>title</h2></div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><p>text</p></div>
</div>
</div>
</section>
......
<?php get_footer(); ?>
所以我的问题是:如何向特定部分添加内容?寻找答案,但找不到好的工作实例。
答案 0 :(得分:0)
在每个部分中都需要get_posts()循环
<?php
$args = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><h2>
<?php the_title(); ?>
</h2></div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><h2>
<?php the_content(); ?>
</h2></div>
<?php endforeach;
wp_reset_postdata();?>
根据需要编辑$ args
更新: 如果它是每个部分中的固定内容,我只需为每个部分创建一个新的wordpress页面。然后你可以在index.php
中run a loop这样<?php
$mypages = get_pages( array( 'include' => '1, 2, 3, 4', 'sort_column' => 'post_title', 'sort_order' => 'asc' ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( 'the_content', $content );
?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2></div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><?php echo $content; ?></div>
<?php
}
?>
将“1,2,3,4”替换为上面创建的新页面ID。