将内容应用于wordpress主题部分


Apply content to wordpress theme sections

有人帮忙!我是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(); ?>

所以我的问题是:如何将内容添加到特定部分?寻找答案,但找不到好的例子。

在的每个部分中都需要一个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 中运行这样的循环

<?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
    }   
?>

用上面创建的新页面ID替换"1、2、3、4"。