Adding Content Areas to Custom Page Template

Thank you all for your help and direction. I decided to go a different route, using a post category for the home page sections. It is not exactly what I wanted to do but seemed the most expedient way to achieve the end result I was looking for. It is easy for the client to update, although not as easy as if I had been successful in achieving my initial goal of updating the template page editor to add three sections. I am still going to work on that and your information will get me started so thank you.

In the meantime, I am calling to each post category in the template page.
I am using the code below, I am sure there is a way to fine tune the code so that it is not as bulky. (please feel free to educate me if you have some suggestions)

Either way it seems to work well.

<!--Header Home Part One-->
<div class="home1">
<?php
$my_query = new WP_Query( 'cat=9' );
$args = array( 'posts_per_page' => 1 );
if ( $my_query->have_posts() ) { 
while ( $my_query->have_posts() ) { 
    $my_query->the_post();
}
}
?>
<h1><a href="https://wordpress.stackexchange.com/questions/159942/<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
<?php wp_reset_postdata(); ?>
<!--/home1--></div>
<!--Header Home Part two-->
<div class="home2">
<?php
$my_query = new WP_Query( 'cat=10' );
$args = array( 'posts_per_page' => 1 );
if ( $my_query->have_posts() ) { 
while ( $my_query->have_posts() ) { 
    $my_query->the_post();
}
}
?>
<h1><a href="https://wordpress.stackexchange.com/questions/159942/<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
<?php wp_reset_postdata(); ?>
<!--/home2--></div>
<!--Header Home Part Three-->
<div class="home3">
<?php
$my_query = new WP_Query( 'cat=11' );
$args = array( 'posts_per_page' => 1 );
if ( $my_query->have_posts() ) { 
while ( $my_query->have_posts() ) { 
    $my_query->the_post();
}
}
?>
<h1><a href="https://wordpress.stackexchange.com/questions/159942/<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
<?php wp_reset_postdata(); ?>
<!--/home3--></div>

Thank you again and please, do not hesitate to educate me if you think the above code could be better written. I am learning as I go and appreciate any and all help!

Leave a Comment