如何把github社区账号信息做成卡片,放到想放的位置,该如何做呢?
把下面代码放到functions.php中
// 获取Github信息
function getGithub($userName){
$url = 'https://api.github.com/users/'.$userName;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //TRUE 将curl_exec()获取的信息以字符串返回,而不是直接输出。
$header = ['User-Agent: php test']; //设置一个你的浏览器agent的header
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, 0); //返回response头部信息
curl_setopt($ch, CURLINFO_HEADER_OUT, true); //TRUE 时追踪句柄的请求字符串,从 PHP 5.1.3 开始可用。这个很关键,就是允许你查看请求header
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$array_data = json_decode($result,true);
$html='<div class="githubCart clearfix"><img class="githubAvatar" src="'.$array_data['avatar_url'].'" alt="'.$array_data['name'].'" width="84" height="84" /><dl class="githubDetail"><dd>Github:<a href="'.$array_data['html_url'].'">'.$array_data['name'].'</a></dd><dt>Repositories:'.$array_data['public_repos'].'</dt><dt>Followers:'.$array_data['followers'].'</dt><dt>Updated:'.date("Y-m-d H:i", strtotime($array_data['updated_at'])).'</dt></dl><p>'.$array_data['bio'].'</p></div>';
echo $html;
};
把下面的代码放在CSS中:
/* githubCart */
.githubCart{
transition: 0.5s;
margin-bottom: 10px;
border: 1px solid #eee;
padding: 10px;
}
.githubCart:hover{
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.githubAvatar{
float: left;
margin-right: 10px;
}
.githubDetail{
margin: 0;
line-height: 21px;
}
.githubCart p{
margin: 10px 0 0 0;
border-top: 1px solid #eee;
padding-top: 10px;
font-size: 1.6em;
}
在需要调用的地方引用:
//lovelu是我的用户名,改成自己的就好了
<?php getGithub(lovelu) ?>


没有回复内容