Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created November 25, 2018 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandanote-info/ee6d3a1a0fc171cc33812eec343632d5 to your computer and use it in GitHub Desktop.
Save pandanote-info/ee6d3a1a0fc171cc33812eec343632d5 to your computer and use it in GitHub Desktop.
データベースからGitHubについての情報を読み出し、Wordpress用の簡易ウィジェットを作成するためのPython3のプログラム。
<?php
function create_githubrepo_widget() {
global $wpdb;
$sql = 'select name, html_url, description from gitrepo';
$rows = $wpdb->get_results($sql, ARRAY_A);
$snippet = '<div style="width:305px;margin: 0 auto;">';
foreach($rows as $row) {
$url = $row["html_url"];
$name = $row["name"];
if ($name == "pandanote-info.github.io") {
$url = "https://sidestory.pandanote.info/";
$name = "sidestory.pandanote.info";
}
$snippet .= '<a class="pandanote-info-github" href="'.$url.'"><span style="color:#1E3E8A;font-weight:bold;font-size:130%;">'.$name.'</span></a><br/>'.$row["description"].'<hr/>';
}
return $snippet . '</div><div class="clear"></div>';
}
add_shortcode('create-githubrepo-widget','create_githubrepo_widget');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment