Emile
Emile

Reputation: 3484

Setting a default structure for a Wordpress post

Background

I am looking to have thousands of posts that are of the same structure. To do this, I want my Wordpress posts to have the right structure setup so that there little copying and pasting.

An example post being, each post having the following-

My Questions

  1. How do you create a standard post structure within a Wordpress Post? Meaning - I want to have this structure setup when I click "New Post" so that I do not have to copy and paste each time.

  2. Is there a way to setup a button so that I could click "Add a step" and it would then insert the appropriate HTML/CSS to input a new step in the section for steps?

Upvotes: 0

Views: 105

Answers (1)

Ali_k
Ali_k

Reputation: 1661

I think you're looking for WordPress templates. Add a files to you theme directory, give it a name (template-default-structure.php). Inside the file you created you need to have the basic content like this:

<?php
/*
    Template Name: Default Structure
*/
?>

<?php wp_head(); ?>

<?php

// All your code here

?>

<?php wp_footer(); ?>

in the content area you'll add all the html and PHP for your page once and then apply the template from the page editor:

enter image description here

You'll need to add some fields to the page post type that you can use as source to the data you'll be displaying in the content area.

I'd suggest using a library like CMB2 if you don't know where to start.

To make life easier for you, I wrote the structure for you, you'll only need to create meta fields and identify them. Here is how the template would look like:

<?php
/*
    Template Name: Default Structure
*/
?>
<?php wp_head(); ?>

<h2>Summary</h2>
<?php 
    $summary_content = get_post_meta( get_the_ID(), 'the_id_of_summary_content', 1 ) );
    echo $summary_content;
?>
<h2>History</h2>
<?php 
    $history_content = get_post_meta( get_the_ID(), 'the_id_of_history_content', 1 ) );
    echo $history_content;
?>
<h2>Requirements</h2>
<?php 
    $requirements_content = get_post_meta( get_the_ID(), 'the_id_of_requirements_content', 1 ) );
    echo $requirements_content;
?>
<h2>Installation Instructions</h2>
<?php 
    $step1_img = get_post_meta( get_the_ID(), 'the_id_of_step1_img', 1 ) );
    $step1_content = get_post_meta( get_the_ID(), 'the_id_of_step1_content', 1 ) );
    $step2_img = get_post_meta( get_the_ID(), 'the_id_of_step2_img', 1 ) );
    $step2_content = get_post_meta( get_the_ID(), 'the_id_of_step2_content', 1 ) );
    $step3_img = get_post_meta( get_the_ID(), 'the_id_of_step3_img', 1 ) );
    $step3_content = get_post_meta( get_the_ID(), 'the_id_of_step3_content', 1 ) );
?>
<div class="step1">
<h3>Step 1</h3>
<div class="stepimg"><img src="<?php echo $step1_img; ?>"></div>
<div class="stepcontent"><?php echo $step1_content; ?></div>
</div>

<div class="step2">
<h3>Step 2</h3>
<div class="stepimg"><img src="<?php echo $step2_img; ?>"></div>
<div class="stepcontent"><?php echo $step2_content; ?></div>
</div>

<div class="step3">
<h3>Step 3</h3>
<div class="stepimg"><img src="<?php echo $step3_img; ?>"></div>
<div class="stepcontent"><?php echo $step3_content; ?></div>
</div>

<h2>Notes</h2>
<?php 
    $notes_content = get_post_meta( get_the_ID(), 'the_id_of_notes_content', 1 ) );
    echo $notes_content;
?>
<?php wp_footer(); ?>

Upvotes: 2

Related Questions