0

快速提问。我想为每条评论添加一个“分享”按钮,以便可以在 facebook 上分享一条评论及其内容。我已经为自定义 html 设置了我自己的 comments.php 回调函数。因此已经可以回显所有评论内容(网址、作者、日期等),但在分享时,facebook 总是会抓取帖子内容。尝试使用 open graph facebook html 和 addanyshare 插件添加共享按钮。没有成功。有没有我错过的特殊插件?

如果你们需要任何其他信息,请告诉我。

提前感谢您的帮助。

最好的迈克尔

functions.php - 为自定义 html 添加了这个,并为社交媒体插件添加了短代码

function mytheme_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
    $tag       = 'div';
    $add_below = 'comment';
} else {
    $tag       = 'li';
    $add_below = 'div-comment';
}?>
<<?php echo $tag; ?> <?php comment_class( empty( 
$args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php 
comment_ID() ?>"><?php 
if ( 'div' != $args['style'] ) { ?>
    <div id="div-comment-<?php comment_ID() ?>" class="comment-body"> 
<?php
} ?>
    <?php 
    if ( $comment->comment_approved == '0' ) { ?>
        <em class="comment-awaiting-moderation"><?php _e( 'Your 
 comment is awaiting moderation.' ); ?></em><br/><?php 
    } ?>


    <?php comment_text(); ?>   
    <?php echo do_shortcode("[TheChamp-Sharing]"); ?>

    <div class="comment-author vcard">- <?php 
        if ( $args['avatar_size'] != 0 ) {
            echo get_avatar( $comment, $args['avatar_size'] ); 
        } 
        printf( __( '<cite class="fn">%s</cite> <span 
 class="says">says:</span>' ), get_comment_author_link() ); ?> / <?php
            /* translators: 1: date, 2: time */
            printf( 
                __('%1$s'), 
                get_comment_date()
            ); ?>
       </div>
    <div class="share"> 



    </div>
    <div class="reply"><?php 
            comment_reply_link( 
                array_merge( 
                    $args, 
                    array( 
                        'add_below' => $add_below, 
                        'depth'     => $depth, 
                        'max_depth' => $args['max_depth'] 
                    ) 
                ) 
            ); ?>
    </div><?php 
if ( 'div' != $args['style'] ) : ?>
    </div><?php 
endif;
}   

评论.php

<?php wp_list_comments( 'type=comment&style=div&callback=mytheme_comment' ); ?>
4

0 回答 0