【发布时间】:2016-10-29 13:16:49
【问题描述】:
我正在使用this 来显示一些推文。
使用here 所示的覆盖过滤器后,它会使自然发生的时间戳消失。
作者给我们提供了一个示例,您可以使用它来覆盖默认标记,如下所示:
add_filter('latest_tweets_render_tweet', function( $html, $date, $link, array $tweet ){
$pic = $tweet['user']['profile_image_url_https'];
return '<p class="my-tweet"><img src="'.$pic.'"/>'.$html.'</p><p class="my-date"><a href="'.$link.'">'.$date.'</a></p>';
}, 10, 4 );
这是我的版本:
add_filter('latest_tweets_render_tweet', function($html){
return
'<div class="row">
<div class="small-1 columns twitter-icon-wrap">
<i class="fa fa-twitter tweet-icon fa-2x fa-pull-left"></i>
</div>
<div class="small-11 columns tweet-wrap">'.$html.'</div>
<p class="tweet-details"><a href="" target="_blank"></a></p>
</div>';
}, 10 , 1 );
如果我在函数中的$html 变量之后添加$date,例如:
add_filter('latest_tweets_render_tweet', function($html, $date)
然后我收到警告:
Warning: Missing argument 2 for ******\******\Extras\{closure}(), called in /srv/www/*********/current/web/wp/wp-includes/plugin.php on line 235 and defined in /srv/www/*******/current/web/app/themes/*********/lib/extras.php on line 144
第 144 行是add_filter('latest_tweets_render_tweet', function($html)
如果我随后将 $date 变量添加到返回的 HTML 中而忽略警告,则会收到错误:
Notice: Undefined variable: date in.....
虽然是警告,但仍然没有显示日期。如何让日期重新出现?
【问题讨论】:
标签: php html wordpress twitter