背景
我希望有数千个具有相同结构的帖子。要做到这一点,我希望我的Wordpress帖子具有正确的结构设置,以便几乎没有复制和粘贴。
一个示例帖子,每个帖子都有以下内容 -
我的问题
如何在Wordpress帖子中创建标准帖子结构?含义 - 当我点击" New Post"我想要这个结构设置。这样我每次都不需要复制和粘贴。
有没有办法设置按钮,以便我可以点击"添加步骤"然后它会插入适当的HTML / CSS来输入步骤中的新步骤吗?
答案 0 :(得分:2)
我认为您正在寻找WordPress模板。将文件添加到主题目录,为其命名(template-default-structure.php)。在您创建的文件中,您需要具有以下基本内容:
<?php
/*
Template Name: Default Structure
*/
?>
<?php wp_head(); ?>
<?php
// All your code here
?>
<?php wp_footer(); ?>
在内容区域中,您只需为页面添加所有html和PHP,然后从页面编辑器应用模板:
您需要在页面帖子类型中添加一些字段,以便将其用作您将在内容区域中显示的数据的来源。
如果您不知道从哪里开始,我建议使用像CMB2这样的库。
为了让您的生活更轻松,我为您编写了结构,您只需要创建元字段并识别它们。以下是模板的外观:
<?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(); ?>