您现在的位置是:首页 > 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删除xmlrpc.php防DDOS攻击的有效方法
可能很多WordPress用户都不知道这个xmlrpc.php是什么,简单地说就是Wordpress 为手机等客户端提供的接口文件,早期的Wordpress 这个接口就是个万恶之源
从零开始搭建个人博客Wordpress
在博客园写了有一年的博客了,也想换换新口味,wordpress的众多的主题和个性化设置非常符合我的喜好,所以捣鼓了一天也算是把它搭好了。
WordPress上传文件类型限制怎么解决
文件类型不符合安全规则。试试别的文件。这种错误是由于WordPress中做了文件上传格式的限制,这种限制可以在WordPress中的wp-include/functions.php的get_allowed_mime_types
Godaddy服务器安装WordPress的方法步骤
设置GoDaddy主机帐号。你在GoDaddy购买域名或者主机时,会被要求创建一个GoDaddy帐号。GoDaddy帐号是用来管理你在GoDaddy购买的所有产品,包括主机、域名、SSL等
相关源码
-
pbootcms(自适应)SEO优化排名服务公司网站模板核心定位为SEO排名服务商打造的营销型网站框架,集成PbootCMS开源系统的高效管理能力与SEO最佳实践方案,助力企业快速建立专业的技术服务形象。查看源码 -
(自适应)挖掘机大型采矿设备pbootcms网站源码下载本模板基于PbootCMS系统开发,专为重型机械设备行业设计,特别适合挖掘机、采矿设备、工程机械等工业设备展示。采用响应式布局技术,确保各类设备参数和图片在不同终端上都能清晰展示。查看源码 -
帝国cms7.2淘宝客导购自媒体博客网站模板源码本模板基于帝国CMS7.2内核深度开发,为淘宝客、商品导购类自媒体及博客网站设计。通过可视化后台管理,可快速搭建具备商品推荐、比价功能的内容平台,帮助用户实现流量高效转化。查看源码 -
帝国cms7.5文库范文/付费下载/复制付费/带支付源码免费下载本模板为文库、文档分享、知识付费类平台设计,提供完整的内容变现解决方案。系统支持多种内容展示与付费模式,满足不同场景下的内容价值转化需求,帮助平台实现内容资源的有效管理和商业化运营。查看源码 -
(自适应响应式)蓝色勘察设计院机构单位商会协会pbootcms模板下载本模板基于PbootCMS系统开发,为勘察设计院所、工程咨询单位设计,特别适合展示设计成果、技术服务和项目案例。采用响应式技术,确保设计图纸和方案以及文案在不同设备上都能清晰展示。查看源码 -
(PC+WAP)压缩机离心风机红色机械设备营销型网站pbootcms模板基于PbootCMS开发的压缩机/离心风机专用模板,助力机械设备企业构建高效营销平台;模板可编辑压缩机参数表、风机性能曲线等专业展示模块查看源码
| 分享笔记 (共有 篇笔记) |

