您现在的位置是:首页 > cms教程 > WordPress教程WordPress教程
wordpress设计单页建立公司团队页的实现方法
袁修纯2025-02-10WordPress教程已有人查阅
导读目前有很多使用wordpress开发网站的公司,都需要一个专门介绍公司团队成员的页面,可以说有许多web开发者都会遇见或者开发过此类页面,下面就来分享通过wordpress页面和字段来创
目前有很多使用wordpress开发网站的公司,都需要一个专门介绍公司团队成员的页面,可以说有许多web开发者都会遇见或者开发过此类页面,下面就来分享通过wordpress页面和字段来创建公司管理团队页面的方法,该方法由Kevin Leary.所提供,本人亲自尝试过,对于创建团队页面来说,该方法确实是一种非常高效灵活,今天借此来分享给大家。
如果你想查看最终的页面效果,可以点击查看以下链接。
团队页面效果
在wordpress中创建和管理团队页面将会涉及到以下方法
1. 自定义发布类型 Custom post type (例如 team)
2. 自定义分类 Custom taxonomy 用于筛选 (例如 department)
3. 创建一个 meta box UI 用于管理自定义字段 (例如 position, email, phone, and social media links)
下面就让我们来为wordpress主题创建一个名为 Meet Our Team 的自定义页面模版
第一步
在我们开始之前,需要澄清几件事情,以下添加的自定义发布类型 Custom post type和自定义分类 Custom taxonomy的代码将直接添加到functions.php文件中,我将详细的介绍整个添加的过程。
添加Custom post type和Custom taxonomy
第一步就是注册一个新的文章发布类型例如 team,如果你需要进行过滤或者分类你还需要注册一个taxonomy分类,例如公司部门等等。
这个新添加的文章发布类型会在wordpress admin后台添加一个新的菜单栏目,用于区分默认的文章发布类型以及页面发布类型。
自定义分类taxonomy将会为之前创建好的team posts添加一个新的分类,让你能够在team的文章发布类型中进行一定程度的分类和过滤。当你公司的团队逐渐增大时,部门越来越多时,你就会发现使用该方法的好处了。
Meta Box自定义字段
现在我们在wordpress中已经拥有了一个新的Team Profiles菜单,我们现在开始需要在每一个团队发布页面中添加自定义字段,在以往大部分的公司项目中,团队介绍页面一般需要以下几个重要的字段
Position
Email
Phone
Twitter
LinkedIn
为了管理内容,我倾向于为团队发布页面添加一个新的可编辑的自定义字段UI页面,方便管理员和作者随时添加自定义字段和修改字段内容。
现在向大家推荐一个目前流行的自定义字段插件Advanced Custom Fields (ACF) plugin,这是一个非常实用的自定义字段插件,使用也简单功能强大,你可以轻松的为各种文章发布类型添加自定义字段,关键是非常容易管理。
如果你想创建 meta box 你需要安装 ACF plugin,安装好插件后就会在后台管理的侧边栏中出现字段栏目,今后你就可以在该栏目中添加和编辑自定义字段,以下是创建字段的效果图。
如果你像我一样懒的话,你可以选择直接导入整理好的XML文件包
1.下载acf-export-team-details.xml.zip压缩文件
2.后台工具栏目中导入xml文件
3.如果需要你应该先安装wordpress导入工具
4.选择上传.xml 文件
就这么多!
如果有不清楚或者疑问你还可以访问开发该插件作者Elliot Condon的网站
现在我们已经拥有了团队管理系统的基本设置,接下来我们还需要一个自定义页面模版用来专门显示团队信息,例如创建一个template-team.php的页面模版,要了解关于自定义页面模版可以参考WordPress.org的自定义模版
循环和显示出团队成员信息资料
为了在template-team.php页面模版中添加和显示成员信息,因此在该模版中添加以下代码。
ACF plugin 插件中将会用到get_field和the_field两种调用方法。该方法就是插件中最常用的,当你想要输出相应字段的时候直接调用它们就好了。
一旦完成代码的添加后,我们就可以在wordpress后台选择名字为Team的自定义页面模版了。
为template-team.php页面模版文件添加独有的css样式
我们可以在function.php文件中添加一个独有的css文件
感谢您的阅读,我希望这边文章能够在一定程度上帮助大家更加高效的使用wordpress自定义字段来创建公司团队页面,对wordpress中的 Custom post types,taxonomies,和meta box 这三个重要的方法有一定程度的了解,如果有更好的方法,欢迎大家留言讨论,以下是关于这边文章完整的文件资料。
如果你想查看最终的页面效果,可以点击查看以下链接。
团队页面效果
在wordpress中创建和管理团队页面将会涉及到以下方法
1. 自定义发布类型 Custom post type (例如 team)
2. 自定义分类 Custom taxonomy 用于筛选 (例如 department)
3. 创建一个 meta box UI 用于管理自定义字段 (例如 position, email, phone, and social media links)
下面就让我们来为wordpress主题创建一个名为 Meet Our Team 的自定义页面模版
第一步
在我们开始之前,需要澄清几件事情,以下添加的自定义发布类型 Custom post type和自定义分类 Custom taxonomy的代码将直接添加到functions.php文件中,我将详细的介绍整个添加的过程。
添加Custom post type和Custom taxonomy
第一步就是注册一个新的文章发布类型例如 team,如果你需要进行过滤或者分类你还需要注册一个taxonomy分类,例如公司部门等等。
这个新添加的文章发布类型会在wordpress admin后台添加一个新的菜单栏目,用于区分默认的文章发布类型以及页面发布类型。
自定义分类taxonomy将会为之前创建好的team posts添加一个新的分类,让你能够在team的文章发布类型中进行一定程度的分类和过滤。当你公司的团队逐渐增大时,部门越来越多时,你就会发现使用该方法的好处了。
Post Type
/**
* Register `team` post type
*/
function team_post_type() {
// Labels
$labels = array(
'name' => _x("Team", "post type general name"),
'singular_name' => _x("Team", "post type singular name"),
'menu_name' => 'Team Profiles',
'add_new' => _x("Add New", "team item"),
'add_new_item' => __("Add New Profile"),
'edit_item' => __("Edit Profile"),
'new_item' => __("New Profile"),
'view_item' => __("View Profile"),
'search_items' => __("Search Profiles"),
'not_found' => __("No Profiles Found"),
'not_found_in_trash' => __("No Profiles Found in Trash"),
'parent_item_colon' => ''
);
// Register post type
register_post_type('team' , array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'menu_icon' => get_stylesheet_directory_uri() . '/lib/TeamProfiles/team-icon.png',
'rewrite' => false,
'supports' => array('title', 'editor', 'thumbnail')
) );
}
add_action( 'init', 'team_post_type', 0 );
Taxonomy
/**
* Register `department` taxonomy
*/
function team_taxonomy() {
// Labels
$singular = 'Department';
$plural = 'Departments';
$labels = array(
'name' => _x( $plural, "taxonomy general name"),
'singular_name' => _x( $singular, "taxonomy singular name"),
'search_items' => __("Search $singular"),
'all_items' => __("All $singular"),
'parent_item' => __("Parent $singular"),
'parent_item_colon' => __("Parent $singular:"),
'edit_item' => __("Edit $singular"),
'update_item' => __("Update $singular"),
'add_new_item' => __("Add New $singular"),
'new_item_name' => __("New $singular Name"),
);
// Register and attach to 'team' post type
register_taxonomy( strtolower($singular), 'team', array(
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'hierarchical' => true,
'query_var' => true,
'rewrite' => false,
'labels' => $labels
) );
}
add_action( 'init', 'team_taxonomy', 0 );
在这个实例当中,是否创建Taxonomy取决与你个人的需要,之所以创建它是因为它可以帮助我们更好的理解和筛选团队部门。Meta Box自定义字段
现在我们在wordpress中已经拥有了一个新的Team Profiles菜单,我们现在开始需要在每一个团队发布页面中添加自定义字段,在以往大部分的公司项目中,团队介绍页面一般需要以下几个重要的字段
Position
Phone
为了管理内容,我倾向于为团队发布页面添加一个新的可编辑的自定义字段UI页面,方便管理员和作者随时添加自定义字段和修改字段内容。
现在向大家推荐一个目前流行的自定义字段插件Advanced Custom Fields (ACF) plugin,这是一个非常实用的自定义字段插件,使用也简单功能强大,你可以轻松的为各种文章发布类型添加自定义字段,关键是非常容易管理。
如果你想创建 meta box 你需要安装 ACF plugin,安装好插件后就会在后台管理的侧边栏中出现字段栏目,今后你就可以在该栏目中添加和编辑自定义字段,以下是创建字段的效果图。
如果你像我一样懒的话,你可以选择直接导入整理好的XML文件包
1.下载acf-export-team-details.xml.zip压缩文件
2.后台工具栏目中导入xml文件
3.如果需要你应该先安装wordpress导入工具
4.选择上传.xml 文件
就这么多!
如果有不清楚或者疑问你还可以访问开发该插件作者Elliot Condon的网站
现在我们已经拥有了团队管理系统的基本设置,接下来我们还需要一个自定义页面模版用来专门显示团队信息,例如创建一个template-team.php的页面模版,要了解关于自定义页面模版可以参考WordPress.org的自定义模版
循环和显示出团队成员信息资料
为了在template-team.php页面模版中添加和显示成员信息,因此在该模版中添加以下代码。
<?php
/**
* Template Name: Team
*/
the_post();
// Get 'team' posts
$team_posts = get_posts( array(
'post_type' => 'team',
'posts_per_page' => -1, // Unlimited posts
'orderby' => 'title', // Order alphabetically by name
) );
if ( $team_posts ):
?>
<section class="row profiles">
<div class="intro">
<h2>Meet The Team</h2>
<p class="lead">“Individuals can and do make a difference, but it takes a team
to really mess things up.”</p>
</div>
<?php
foreach ( $team_posts as $post ):
setup_postdata($post);
// Resize and CDNize thumbnails using Automattic Photon service
$thumb_src = null;
if ( has_post_thumbnail($post->ID) ) {
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'team-thumb' );
$thumb_src = $src[0];
}
?>
<article class="col-sm-6 profile">
<div class="profile-header">
<?php if ( $thumb_src ): ?>
<img src="<?php echo $thumb_src; ?>" alt="<?php the_title(); ?>, <?php the_field('team_position'); ?>" class="img-circle">
<?php endif; ?></div>
<div class="profile-content">
<h3><?php the_title(); ?></h3>
<p class="lead position"><?php the_field('team_position'); ?></p>
<?php the_content(); ?></div>
<div class="profile-footer">
<a href="tel:<?php the_field('team_phone'); ?>"><i class="icon-mobile-phone"></i></a>
<a href="mailto:<?php echo antispambot( get_field('team_email') ); ?>"><i class="icon-envelope"></i></a>
<?php if ( $twitter = get_field('team_twitter') ): ?>
<a href="<?php echo $twitter; ?>"><i class="icon-twitter"></i></a>
<?php endif; ?>
<?php if ( $linkedin = get_field('team_linkedin') ): ?>
<a href="<?php echo $linkedin; ?>"><i class="icon-linkedin"></i></a>
<?php endif; ?></div>
</article><!-- /.profile -->
<?php endforeach; ?>
</section><!-- /.row -->
<?php endif; ?>
为了得到 team post的文章内容,我们使用了get_posts函数,它是一种简单高效的方法,并使用了以下变量和参数来获取相应的内容。
'post_type' => 'team' 搜寻文章发布类型为 'team' 的文章
'posts_per_page' => 50 显示文章的数量上限为50
'orderby' => 'title'根据标题搜寻
'order' =>; 'ASC' 按照字母循序排列显示
一旦我们得到了想要的对象,我们就可以通过循环每一篇发布类型为 team 的文章,就可以按照html结构输出相应的数据内容。ACF plugin 插件中将会用到get_field和the_field两种调用方法。该方法就是插件中最常用的,当你想要输出相应字段的时候直接调用它们就好了。
一旦完成代码的添加后,我们就可以在wordpress后台选择名字为Team的自定义页面模版了。
为template-team.php页面模版文件添加独有的css样式
我们可以在function.php文件中添加一个独有的css文件
/**
* Load CSS for template-team.php
*/
function team_styles() {
if ( is_page_template('template-team.php') )
wp_enqueue_style( 'team-template', get_stylesheet_directory_uri() . '/css/team.css' );
}
add_action( 'wp_enqueue_scripts', 'team_styles', 101 );
css样式代码
/* ==============================================
Team profiles
============================================== */
.profiles {
margin-bottom: -20px;
}
.intro {
padding-left: 140px;
}
.intro h2 {
margin: 0 0 7px;
}
.intro .lead {
line-height: 120%;
font-size: 1.1em;
font-style: italic;
margin: 0 0 35px;
}
.profile {
position: relative;
margin: 0 0 20px;
}
.profile:nth-child(even) {
clear: left;
}
.profile-header {
position: absolute;
top: 0;
}
.profile-header img {
float: left;
}
.profile-content {
font-size: 14px;
padding: 27px 20px 0 0;
line-height: 1.4em;
margin: 0 0 0 125px;
}
.profile-content h3 {
margin: 0;
}
.profile-content .lead {
font-size: 1.3em;
line-height: 100%;
font-style: italic;
margin: 3px 0 20px;
}
.profile-content:before {
content: '';
width: 36px;
height: 3px;
background: #dededc;
position: absolute;
top: 0;
}
.profile-content p {
margin: 0 0 10px;
}
.profile-footer {
position: absolute;
top: 121px;
width: 100px;
text-align: center;
}
.profile-footer a {
line-height: 18px;
margin: 0 3px;
display: inline-block;
}
.profile-footer a:hover i {
color: #595959;
}
.profile-footer a:active i {
color: #000;
}
.profile-footer i {
font-size: 18px;
position: relative;
}
.profile-footer i.icon-envelope {
font-size: 16px;
top: -1px;
}
.profile-footer i.icon-linkedin {
font-size: 16px;
top: -1px;
}
大功告成感谢您的阅读,我希望这边文章能够在一定程度上帮助大家更加高效的使用wordpress自定义字段来创建公司团队页面,对wordpress中的 Custom post types,taxonomies,和meta box 这三个重要的方法有一定程度的了解,如果有更好的方法,欢迎大家留言讨论,以下是关于这边文章完整的文件资料。
本文标签:
很赞哦! ()
相关教程
图文教程
wordpress使用的编程语言是什么
wordpress使用的编程语言是PHP语言,意思就是WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。
Wordpress修改某篇文章ID的SQL语句写法实例
Wordpress修改某篇文章ID的SQL语句是什么?前几天写文章的时候,ID从146直接跳到148,Wordpress是做过处理的ID是会自动连续的
wordpress安装apache和nginx的方法
Apache启动目录:/opt/lampp/bin/httpd配置目录:/opt/lampp/etc/httpd.confMysql启动目录:/opt/lampp/bin/mysqld1.1将wordpress放在系统默认目录下
WordPress网站优化SEO的做法
我们都知道,WordPress是全球较大的blog程序,当然,不仅限与做blog使用,因为它有非常多的各行各业的模板供我们使用,因此,WordPress备受广大站长朋友们的喜爱,但是,WordPress毕竟是外
相关源码
-
帝国cms7.5淘宝客电商品牌特价带手机站带会员模板下载为电商品牌特价展示设计的帝国CMS模板,集成PC端与移动端双平台适配。采用瀑布流商品布局,支持品牌分类聚合展示,突出特价促销视觉冲击力。查看源码 -
(自适应)中英双语配线器材扎带线卡网站pbootcms模板免费下载为线缆管理、电气配线领域打造的响应式网站模板,采用PbootCMS内核开发,可快速搭建企业级产品展示平台,数据实时同步管理。查看源码 -
响应式高端家居家具装修类pbootcms模板网站源码家居装修、空间设计企业打造的营销型网站解决方案,基于PbootCMS内核深度开发。采用前沿响应式架构,适配手机端与PC端浏览体验查看源码 -
(自适应)黑色摄影作品工作室pbootcms模板网站源码下载为风景摄影、个人工作室打造的高端网站模板,基于PbootCMS开源内核开发,采用HTML5自适应架构,PC与移动端实时数据同步,适配各类拍摄作品展示需求。查看源码 -
(PC+WAP)蓝色低碳环保隔断板装修装饰类网站pbootcms源码下载本款基于PbootCMS开发的网站模板为活动隔断板、装修装饰行业打造,特别适合移动隔断、环保隔断、办公分区等产品的展示与推广。查看源码 -
(自适应)html5宽屏电线电缆材料加工制造类企业网站源码下载本模板基于PbootCMS系统开发,特别适合电线电缆、电缆材料及相关加工制造类企业使用。采用HTML5宽屏设计,能够展示各类电缆产品的技术参数和规格详情,帮助客户全面了解产品特性。查看源码
| 分享笔记 (共有 篇笔记) |

