
我以前写了一些代码。 这使您可以查看Twitter关注者的数量。 在本文中,我们将分享更复杂,更优雅的代码,使您可以在WordPress中查看Twitter关注者。 此脚本也由Rust捐赠。
特征
此功能不仅限于关注者的数量。 您可以通过Twitter用户/Show API方法返回的非嵌套值。
缓存有两个级别。
查询的值使用WP选项作为数组保存在数据库中,并持续$ Interval秒。 API响应存储在内存中,因此您可以根据需要查询尽可能多的字段,而无需生成多个API请求。
首先打开主题function.php文件,然后添加以下代码:
forcornrarst_twitter_user($ username,$ field,$ display = false){$ interval = 3600; $ cache = get_option(’rarst_twitter_user’) ? screen_name =’。 urlencode($ username)if(false == $ cache)$ cache = array(); $ cache [$ username] [$ field] = null; $ cache [$ username] [‘lastcheck’] = 0;} //如果undestedif($ cache [$ username] [‘lastcheck’] $ Interval)){// memorystatic $ memorycache; {$ result = wp_remote_retrieve_body(wp_remote_body(wp_remote_request($ url)); $ data = json_decode($ result); if(is_object($ data) ){//更新所有fields,请求($ cache [$ username]为$ key => $ value),如果(ISSET($ data-> $ key))$ cache [$ username] [$ key] = $ data-> $ $ key; [$ userName] [‘lastcheck’] = time();} else {$ cache [$ username] [‘lastcheck’] = time()+60;} update_option(’rarst_twitter_user’,$ cache’,$ cache);} !!
经过
仅一键使用WordPress
用法
粘贴功能后,您现在可以在您喜欢的WordPress模板文件中使用代码。 只需粘贴以下代码:
echoorarst_twitter_user(’wpbeginner’,’name’)。 具有’.rarsst_twitter_user(’wpbeginner’,’collasters_count’)。 “关注者” .rarsst_twitter_user(’wpbeginner’,’status_count’)。 更新。 ‘;
经过
仅一键使用WordPress
上面的代码应该看起来像这样:
自1300年更新以来,WP初学者拥有5846个关注者。
如何学习PHP? 如何开始PHP? 我在哪里可以学习PHP? 如何立即学习PHP? 不用担心,这是PHP速度学习教程(向初学者学习)。 需要它的朋友可以保存和下载并学习它!
下载
草根吧VPS_最新VPS信息参考
PHP快速学习视频