将注册用户的评论链接到他们的个人资料页面

时间:2013-04-04 作者:theshorttree

我正在试图找到一种方法来链接来自的评论中的“用户名”registeredlogged in 用户访问他们的个人资料页面,而不是他们的网站URL。以及未注册用户对其网站URL的评论。

这可能吗?我的wordpress版本是3.5.1,我使用的是默认主题二十一。

下面是函数“TwentyEleven\\u comment”的代码:

<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    <article id="comment-<?php comment_ID(); ?>" class="comment">
        <header class="comment-meta comment-author vcard">
            <?php
                echo get_avatar( $comment, 44 );
                printf( \'<cite class="fn">%1$s %2$s</cite>\',
                    get_comment_author_link(),
                    // If current post author is also comment author, make it known visually.
                    ( $comment->user_id === $post->post_author ) ? \'<span> \' . __( \'Post author\', \'twentytwelve\' ) . \'</span>\' : \'\'
                );
                printf( \'<a href="%1$s"><time datetime="%2$s">%3$s</time></a>\',
                    esc_url( get_comment_link( $comment->comment_ID ) ),
                    get_comment_time( \'c\' ),
                    /* translators: 1: date, 2: time */
                    sprintf( __( \'%1$s at %2$s\', \'twentytwelve\' ), get_comment_date(), get_comment_time() )
                );
            ?>
        </header><!-- .comment-meta -->

        <?php if ( \'0\' == $comment->comment_approved ) : ?>
            <p class="comment-awaiting-moderation"><?php _e( \'Your comment is awaiting moderation.\', \'twentytwelve\' ); ?></p>
        <?php endif; ?>

        <section class="comment-content comment">
            <?php comment_text(); ?>
            <?php edit_comment_link( __( \'Edit\', \'twentytwelve\' ), \'<p class="edit-link">\', \'</p>\' ); ?>
        </section><!-- .comment-content -->

        <div class="reply">
            <?php comment_reply_link( array_merge( $args, array( \'reply_text\' => __( \'Reply\', \'twentytwelve\' ), \'after\' => \' <span>&darr;</span>\', \'depth\' => $depth, \'max_depth\' => $args[\'max_depth\'] ) ) ); ?>
        </div><!-- .reply -->
    </article><!-- #comment-## -->
<?php
    break;
endswitch; // end comment_type check
}
endif;

3 个回复
最合适的回答,由SO网友:fuxia 整理而成

不久前,我已经为此编写了一个解决方案:

<?php # -*- coding: utf-8 -*-
/**
 * Plugin Name: T5 Comment author URI to blog author page
 * Description: Changes the comment author URI to the blog’s author archive
 * Version:     2012.07.18
 * Author:      Fuxia Scholz
 * Author URI:  https://fuxia.me
 * License:     MIT
 * License URI: http://www.opensource.org/licenses/mit-license.php
 */

if ( ! function_exists( \'t5_comment_uri_to_author_archive\' ) )
{
    add_filter( \'get_comment_author_url\', \'t5_comment_uri_to_author_archive\' );

    function t5_comment_uri_to_author_archive( $uri )
    {
        global $comment;

        // We do not get the real comment with this filter.
        if ( empty ( $comment )
            or ! is_object( $comment )
            or empty ( $comment->comment_author_email )
            or ! $user = get_user_by( \'email\', $comment->comment_author_email )
        )
        {
            return $uri;
        }

        return get_author_posts_url( $user->ID );
    }
}

SO网友:gdaniel

如果用户已经登录,那么只需指向管理页面即可让他们看到自己的个人资料。该链接可以指向:

用户配置文件页面:http://yoursite.com/wp-admin/profile.php

你需要编辑你的评论模板来检查用户是否登录(如果我没有弄错的话,评论模板已经检查过了,这取决于主题是否编码良好)。如果没有,您可以使用:

is_user_logged_in()
您可以通过以下链接获取作者的评论:

comment_author_link()

SO网友:montrealist

在s\\u ha\\u dum的评论的指导下,以下是如何生成指向作者存档页面的链接(列出该作者的所有帖子)。你需要把代码放进去functions.php\'stwentytwelve_comment 功能,在哪里$comment 对象可用。

$uname = get_the_author_meta( \'user_login\', $comment->user_id ); // get username
echo site_url(\'/author/\' . $uname);
至于comment_author_link, 它将为您提供一个指向作者在其个人资料信息中提供的URL的链接。如果他们没有这样做,那么它只会返回作者的名字。

结束

相关推荐

不能选中“Allow Comments”框

我已经注册了一个自定义帖子类型,确保“支持”中有“评论”,并且允许在“设置”->“讨论”下的新帖子上发表评论。我确实看到了允许评论和允许回溯/ping的复选框。如果我选中“允许评论”,则更新/发布帖子,it automatically gets unchecked.我不知道为什么。我找到的唯一解决方案是通过SQL查询。我可以在保存后添加一个操作来运行查询,但我想知道问题出在哪里。register_post_type( \'ott_products\', array(