1

ここには非常に単純な php ループがあり (以下を参照)、img クラス "yearofstudy" の後に 2 つの好きなカウンターと嫌いなカウンターを表示したいと考えています。ただし、テキストは画像の後に表示されません。実際の HTML の後に配置されていても。

コメントの Like と Dislike は、それらが表示される WP ループを作成するため、機能するために tis 関数内にある必要があります。基本的に、これを再配置して、好き嫌いがループに表示されるようにする必要がありますが、画像の後に表示されます。

私はこれを何時間も見つめていて、すべてのオンラインを見てきましたが、まだ何も見つかりません.

// Add the comment meta (saved earlier) to the comment text 
// You can also output the comment meta values directly in comments template  

add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){

    $plugin_url_path = WP_PLUGIN_URL;

    if( $commenttitle = get_comment_meta( get_comment_ID(), 'title', true ) ) {
        $commenttitle = '<strong>' . esc_attr( $commenttitle ) . '</strong><br/>';
        $text = $commenttitle . $text;
    } 

    if( $commentrating = get_comment_meta( get_comment_ID(), 'rating', true ) ) {
        $commentrating = '<p class="comment-rating">    <img src="'. $plugin_url_path .
        '/ExtendComment/images/'. $commentrating . 'star.gif" class="yearofstudy" /></p><br />';


        $text = $text . $commentrating;
        return $text;   

    // LIKE AND DISLIKE ON COMMENTS     
    if(function_exists('like_counter_c')) { like_counter_c('text for like'); }

    if(function_exists('dislike_counter_c')) { dislike_counter_c('text for dislike'); }     
    }

}

編集:

RecoveringSince2003 によって提供される回答は機能し、好き嫌いを表示しますが、html 画像 yearofstudy の後に関数を表示することはできません。それは前に表示され、これは私が求めているものではありません。

ここにある例については、下にスクロールしてコメント/レビューを確認してください: http://universitycompare.com/universities/anglia-ruskin-university

4

1 に答える 1

0

一見すると、あなたは持っています

if( $commentrating = get_comment_meta( get_comment_ID(), 'rating', true ) ) {
    $commentrating = '<p class="comment-rating">    <img src="'. $plugin_url_path .
    '/ExtendComment/images/'. $commentrating . 'star.gif" class="yearofstudy" /></p><br />';

    $text = $text . $commentrating;
    return $text;   // <-- terminating the execution

    // following code is never being executed
    // LIKE AND DISLIKE ON COMMENTS     
    if(function_exists('like_counter_c')) { like_counter_c('text for like'); }
    if(function_exists('dislike_counter_c')) { dislike_counter_c('text for dislike'); }     
}

そう。returnステートメントは関数の実行を終了しており、その後のコードの残りの部分には到達returnしていません。これらの関数呼び出しがどのように/どのように機能しているかはわかりませんが、これらの行を実行したい場合は、ステートメントをこれらの行の後if(function_exists('like_counter_c'))に移動します。return

$text = $text . $commentrating;
if(function_exists('like_counter_c')) { like_counter_c('text for like'); }
if(function_exists('dislike_counter_c')) { dislike_counter_c('text for dislike'); }
return $text;

アップデート :

画像タグにスタイルを追加します (**yearofstudy**クラスを変更する方法は他にもあります) 。

<img src="'. $plugin_url_path .
    '/ExtendComment/images/'. $commentrating . 'star.gif" class="yearofstudy" style="float:right" />
于 2013-10-17T23:20:10.243 に答える