我这里有一个非常简单的php循环(见下文),并希望两个喜欢和不喜欢的计数器出现在img类"学习年份"之后。但是,文本不会显示在图像之后。即使它放在实际的 HTML 之后。
评论上的喜欢和不喜欢必须在tis函数中才能工作,因为它会在显示它们的位置创建一个WP循环。基本上,我需要帮助重新安排它,以便喜欢和不喜欢出现在循环中但在图像之后。
非常感谢任何帮助,我已经盯着这个看了几个小时,并且在网上看了每一个,仍然没有找到任何东西。
// 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 图像学习年份之后。它出现在之前,这不是我所追求的。
有关示例,请参阅此处,请确保向下滚动以查看评论/评论:http://universitycompare.com/universities/anglia-ruskin-university
乍一看,你有
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" />