Address
304 North Cardinal St.
Dorchester Center, MA 02124
Work Hours
Monday to Friday: 7AM - 7PM
Weekend: 10AM - 5PM
Address
304 North Cardinal St.
Dorchester Center, MA 02124
Work Hours
Monday to Friday: 7AM - 7PM
Weekend: 10AM - 5PM
wordpress作者的相关函数调用代码
<?php the_author(); ?> 显示文章的作者
2.<?php the_author_description(); ?> 显示文章作者的描述(作者个人资料中的描述)
3.<?php the_author_login(); ?> 显示文章作者的登录名
4.<?php the_author_firstname(); ?> 显示文章作者的firstname(名)
5.<?php the_author_lastname(); ?> 显示文章作者的lastname(姓)
6.<?php the_author_nickname(); ?> 显示文章作者的昵称
7.<?php the_author_ID(); ?> 显示文章作者的ID号
8.<?php the_author_email(); ?> 显示文章作者的电子邮箱
9.<?php the_author_url(); ?> 显示文章作者的网站地址
10.<?php the_author_link (); ?>(添加于2.1版本) 显示一个以文章作者名为链接名,链接地址为文章作者的网址的链接。
11.<?php the_author_icq(); ?> (不推荐使用) 显示文章作者的icq
12.<?php the_author_aim(); ?> 显示文章作者的aim
13.<?php the_author_yim(); ?> 显示文章作者的yim
14.<?php the_author_msn(); ?> (不推荐使用) 显示文章作者的msn
15.<?php the_author_posts(); ?> 显示文章作者已发表文章的篇数
16.<?php the_author_posts_link(); ?> 显示一个链接到文章作者已发表文章列表的链接
17.<?php list_authors(); ?> (不推荐使用) 显示blog所有作者和他们的相关信息。完整函数如下:
1. 一个不错的解决方法是将WordPress作者存档链接中的用户名改为昵称。
修改方法如下:
/**
* 将WordPress作者存档链接中的用户名改为昵称
* https://www.wpdaxue.com/use-nickname-for-author-slug.html
*/
//使用昵称替换用户名,通过用户ID进行查询
add_filter( ‘request‘, ‘wpdaxue_request’ );
function wpdaxue_request( $query_vars )
{
if ( array_key_exists( ‘author_name’, $query_vars ) ) {
global $wpdb;
$author_id = $wpdb->get_var( $wpdb->prepare( “SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key=’nickname’ AND meta_value = %s”, $query_vars[‘author_name’] ) );
if ( $author_id ) {
$query_vars[‘author’] = $author_id;
unset( $query_vars[‘author_name’] );
}
}
return $query_vars;
}
//使用昵称替换链接中的用户名
add_filter( ‘author_link’, ‘wpdaxue_author_link’, 10, 3 );
function wpdaxue_author_link( $link, $author_id, $author_nicename )
{
$author_nickname = get_user_meta( $author_id, ‘nickname’, true );
if ( $author_nickname ) {
$link = str_replace( $author_nicename, $author_nickname, $link );
}
return $link;
}
如果不希望蜘蛛爬取这些链接:给作者链接添加nofollow
打开wp-includes/author-template.php
查找
‘<a href=”%1s”title=”s”>%3s</a>′,只需加个nofollow标签,例如:′<ahref=”s” title=”%2s”rel=”nofollow”>s</a>’
2.更改wordpress主题内的function.php文件,在php循环内增加如下代码:
//给 the_author_post_link 生成的链接加上 rel=”nofollow”
add_filter(‘the_author_posts_link’,’cis_nofollow_the_author_posts_link’);
function cis_nofollow_the_author_posts_link ($link) {
return str_replace(‘<a href=’,'<a rel=”nofollow” href=’, $link);
}
更改/移除WordPress作者存档页面的前缀“author”
3.可以在根目录下新建一个作者页面author.php