给WordPress文章添加多个特色图片插件 – Multiple Post Thumbnails

站长朋友们在进行的过程中,往往需要给文章设置多个特色图片(缩略图)。我们可以通过自定义字段来实现此功能,但是使用起来不太方便,没有默认的设置特色图片的方式那么好用。这篇WordPress教程里,我们就向大家介绍一款好用的插件 – Multiple Post Thumbnails。

wpt

此款可以给WordPress文章添加多个特色图片,是一款面向WordPress开发者的插件,它定义了一套在后台增加多个缩略图的机制,并且在前端调用新增缩略图的方法,而且它定义的后台空间支持WordPress的图片上传方式,使用起来和默认的特色图片效果基本一致。

插件安装方法:

1. 在WordPress后台的插件部分,搜索 Multiple Post Thumbnails 在线安装或者上传到服务器空间。
2. 激活插件

插件使用方法

1. 注册新的特色图片,切换到主题目录,打开functions.PHP文件,加入以下代码

Crayon-5c891ce3a8a65466033165" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891ce3a8a65466033165-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce3a8a65466033165-2">2
Crayon-num" data-line="Crayon-5c891ce3a8a65466033165-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce3a8a65466033165-4">4
Crayon-num" data-line="Crayon-5c891ce3a8a65466033165-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce3a8a65466033165-6">6
Crayon-num" data-line="Crayon-5c891ce3a8a65466033165-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce3a8a65466033165-8">8
Crayon-num" data-line="Crayon-5c891ce3a8a65466033165-9">9
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891ce3a8a65466033165-1">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-e">class_existsCrayon-sy">(Crayon-s">'MultiPostThumbnails'Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891ce3a8a65466033165-2">Crayon-h">Crayon-r">newCrayon-h"> Crayon-e">MultiPostThumbnailsCrayon-sy">(
Crayon-line" id="Crayon-5c891ce3a8a65466033165-3">Crayon-h">Crayon-t">arrayCrayon-sy">(
Crayon-line Crayon-striped-line" id="Crayon-5c891ce3a8a65466033165-4">Crayon-h">Crayon-s">'label'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'Secondary Image'Crayon-sy">,
Crayon-line" id="Crayon-5c891ce3a8a65466033165-5">Crayon-h">Crayon-s">'id'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'secondary-image'Crayon-sy">,
Crayon-line Crayon-striped-line" id="Crayon-5c891ce3a8a65466033165-6">Crayon-h">Crayon-s">'post_type'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'post'
Crayon-line" id="Crayon-5c891ce3a8a65466033165-7">Crayon-h">Crayon-sy">)
Crayon-line Crayon-striped-line" id="Crayon-5c891ce3a8a65466033165-8">Crayon-h">Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891ce3a8a65466033165-9">Crayon-sy">}

注意:你可以通过将 post_type 设置为 page,给静态页面设置第二张特色图片缩略图),或者给自定义日志类型设置多张缩略图

2. 在文章日志页面通过如下代码显示刚才注册的新的特色图片

Crayon-5c891ce3a8a6f613418194" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">single.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-mixed-highlight" title="Contains Mixed Languages">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891ce3a8a6f613418194-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce3a8a6f613418194-2">2
Crayon-num" data-line="Crayon-5c891ce3a8a6f613418194-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce3a8a6f613418194-4">4
Crayon-num" data-line="Crayon-5c891ce3a8a6f613418194-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891ce3a8a6f613418194-6">6
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891ce3a8a6f613418194-1">Crayon-ta">PHPCrayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-e">class_existsCrayon-sy">(Crayon-s">'MultiPostThumbnails'Crayon-sy">)Crayon-sy">)Crayon-h"> Crayon-o">:
Crayon-line Crayon-striped-line" id="Crayon-5c891ce3a8a6f613418194-2">Crayon-h">Crayon-e">MultiPostThumbnails::Crayon-e">the_post_thumbnailCrayon-sy">(
Crayon-line" id="Crayon-5c891ce3a8a6f613418194-3">Crayon-h">Crayon-e">get_post_typeCrayon-sy">(Crayon-sy">)Crayon-sy">,
Crayon-line Crayon-striped-line" id="Crayon-5c891ce3a8a6f613418194-4">Crayon-h">Crayon-s">'secondary-image'
Crayon-line" id="Crayon-5c891ce3a8a6f613418194-5">Crayon-h">Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891ce3a8a6f613418194-6">Crayon-st">endifCrayon-sy">;Crayon-h">

感兴趣的朋友可以下载此款wordpress插件研究一下。

相关文章

我们有时候在定制WORDPRESS主题的时候,由于菜单样式的要求我...
很多朋友在做wordpree主题制作的时候会经常遇到一个问题,那...
wordpress后台的模块很多,但并不是每个都经常用到。介绍几段...
从WordPress4.2版本开始,如果我们在MYSQL5.1版本数据中导出...
很多网友会遇到这样一个问题,就是WordPress网站上传图片、附...
对于经常要在文章中出现代码的IT相关博客,安装一个代码高亮...