用不同的替换作者网址(wordpress)

时间:2009-05-15 16:12:55

标签: wordpress permalinks

我们公司博客中有3位作者,每个作者在个人资料设置中都有自己的网站网址

Mike - http://mike.com
Gelens - http://gelens.com
Admin - http://site.com/company/

个人资料的链接是:

http://site.com/author/Mike/
http://site.com/author/Gelens/
http://site.com/author/Admin/

我需要替换管理员页面的链接,因此,如果某个页面上有<?php the_author_posts_link(); ?>标记,并且作者是管理员,则该链接必须是http://site.com/company/而不是http://site.com/author/Admin/

我该怎么做?

4 个答案:

答案 0 :(得分:3)

看起来the_author_posts_link函数只是调用get_author_posts_url来获取链接,该链接在返回之前通过author_link过滤器传递链接。在您的主题functions.php中,您可以添加类似的内容(未经测试):

add_filter( 'author_link', 'admin_author_link', 10, 3);
function admin_author_link($link, $author_id, $author_nicename) {
    if( $author_id==1 ) {
        $link = 'http://site.com/company/';
    }
    return $link;
}

答案 1 :(得分:3)

我认为最少的胃灼热是wordpress > the_author_meta

让每个用户在wordpress用户个人资料中添加他们的网址,就像您所做的那样。然后在您的主题functions.php中使用the_author_meta('user_url')。请记住,这将回应网址。要将其用作变量,请使用get_the_author_meta('user_url')

以下是我们如何使用二十个主题,这是functions.php

function twentyten_posted_on() {
printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    'meta-prep meta-prep-author',
    sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
        get_permalink(),
        esc_attr( get_the_time() ),
        get_the_date()
    ),
    sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
        get_the_author_meta('user_url'), //changed from get_author_posts_url( get_the_author_meta( 'ID' ) ),
        sprintf( esc_attr__( 'About %s', 'twentyten' ), get_the_author() ),
        get_the_author()
    )
);
}

答案 2 :(得分:1)

用.htaccess重写URL,这可以通过手动编辑.htaccess来实现。

对于使用http://wordpress.org/extend/plugins/redirection/这样的插件的初学者来说更容易,这似乎可以满足您的需求。

答案 3 :(得分:0)

您可以使用http重写来执行此操作。

相关问题