WordPress自定义文章模板插件Custom Post Template简介

  categories:wordpress  tags:,   author:

大家都知道,WordPress发布页面(Page)时支持选择页面模板,那么,如果发布文章也可以选择文章模板,那该是多好的事啊!今天倡萌介绍的 Custom Post Template 和 Single Post Template 插件就可以实现这个功能!

The Single Post Template plugin adds the ability for your theme to include “Post Templates” in much the same way you can add “Page Templates”, allowing you to choose (via a simple dropdown) which post template you want to use, on a per-post basis.

All you need to do, after installing and activating the plugin, is create one or more “Post Templates” in your theme’s folder, and when creating or editing a post, choose the post template that you would like to use. If no post template is selected, the default template will be used.

Custom Post Template

Custom Post Template 是一个WordPress自定义文章模板插件,通过它,你可以制作不同的文章模板文件(类似于 single.php),然后根据不同类型的文章,选择不同的模板文件,是不是很酷?

1.在后台插件安装界面搜索 Custom Post Template 即可在线安装,后者下载 Custom Post Template

2.复制主题的 single.php 文件的代码,在其顶部添加类似下面的代码:

<?php
/*
Template Name Posts: wpdaxue
*/
?>

另存为其他文件名,比如 single-wpdaxue.php (存放位置和 single.php 相同,即主题的根目录),第 3 行冒号后面的 wpdaxue 就是模板名称,你可以自己修改。然后在发布文章时,就可以选择改模板文件:

image

 

  1. single-post-template screenshot 1This is what the top of your new Post Templates should look like
  2. single-post-template screenshot 2This is the new box that this plugin adds to your post edit screen

当然了,要想实现不同的文章样式,你就要自己修改自定义的文章模板文件了。

Single Post Template

Single Post Template 和 Custom Post Template 类似,只是文章模板文件的写法不一样,使用的是:

<?php
/*
Single Post Template: wpdaxue
*/
?>

在后台插件安装界面搜索 Single Post Template 即可现在安装,或者下载 Single Post Template

 

安装

Installation

  1. Upload the entire single-post-template folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Create Post Templates in your theme’s folder, as described in Usage

Usage

After you have installed the plugin, you’ll need to create some Post Templates to use. In order to create a Post Template, either duplicate your default single post template, or create a new template file. Insert the following code at the very top of the file:

<?php
/*
Single Post Template: [Descriptive Template Name]
Description: This part is optional, but helpful for describing the Post Template
*/
?>

See Screenshot #1 for what this might look like in your code editor

Once you have created a new Post Template, either edit or create a new post, and directly underneath the post content box, you should see a new box labeled “Single Post Template”. Choose the Post Template you want to use and publish or update the post.

See Screenshot #2 for what this might look like in your post edit screen



快乐成长 每天进步一点点