Skip to content

Instantly share code, notes, and snippets.

View blockworks's full-sized avatar

Kenichi Kaneko blockworks

View GitHub Profile
@blockworks
blockworks / gist:1047224
Created June 26, 2011 04:03
PHPでユーザーエージェントを使用して機種を識別する
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>ユーザーエージェントで機種を識別する</title>
</head>
<body>
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
@blockworks
blockworks / gist:1066554
Created July 6, 2011 04:18
WordPressカスタム投稿タイプ&カスタム分類のサンプル
<?php
////////////////////////////////////////////////
//カスタム投稿タイプ「物件」の設定
////////////////////////////////////////////////
function add_realestate_type(){
//カスタム投稿タイプ(物件)の設定
$args = array(
'label' => '物件0',
'labels' => array(
'singular_name' => '物件1',
@blockworks
blockworks / gist:1066557
Created July 6, 2011 04:20
文字列をバイナリにしてファイルに保存する(.act)
<?php
$hex_str = "cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffffff0000ff222222cc0000333333ffff
@blockworks
blockworks / gist:1066633
Created July 6, 2011 05:37
先頭の1文字以外の文字をマッチさせる正規表現
//jedit Xの正規表現構文(ruby)にて動作確認。
(?<=.).*
@blockworks
blockworks / gist:1091517
Created July 19, 2011 06:49
WordPressでカスタムフィールドに値を連続挿入する。
//meta_idはnullにすると適したidを振ってくれる。
//特殊記号-+'`&等は、インポートの際、ひっかかるので、削除しておくこと
INSERT INTO `wp_postmeta` (meta_id, post_id, meta_key, meta_value)
VALUES (null,記事ID,'カスタムフィールド名','値'),
(null,記事ID,'カスタムフィールド名','値'),
(null,記事ID,'カスタムフィールド名','値');
@blockworks
blockworks / gist:1128734
Created August 5, 2011 23:03
yuga.jsを改良。tableの列(縦)側にもクラスを振る
//該当部分だけのコードです。ソースを見て、必要な箇所だけコピペで差し替えてください。
//奇数、偶数を自動追加
stripe: function(options) {
var c = jQuery.extend({
oddClass:'odd',
evenClass:'even',
rowoddClass:'rowodd',
rowevenClass:'roweven'
}, options);
@blockworks
blockworks / gist:1148223
Created August 16, 2011 00:47
WordPressで独自指定のタクソノミを複数指定し、その内容をリスト表示する
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'ポストタイプを記述',
'posts_per_page' => 10, //表示件数
'paged' => $paged, //現在何ページ目かを取得
'tax_query' => array( //カスタム分類を複数選択
'relation' => 'AND', //ANDまたはOR
array(
'taxonomy' => 'タクソノミ名を記述',
@blockworks
blockworks / gist:1159105
Created August 20, 2011 13:24
SimpleXMLのメモ
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>テスト</title>
</head>
<body>
<?php
$url = "http://b.hatena.ne.jp/hotentry.rss";
$str = file_get_contents( $url );
@blockworks
blockworks / gist:1160516
Created August 21, 2011 11:55
Wordpressのページネーション
///////////////////////////////////////
//functions.phpに以下を記述
///////////////////////////////////////
function pagination($pages = '', $range = 2){
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == ''){
global $wp_query;
$pages = $wp_query->max_num_pages;
@blockworks
blockworks / gist:1194583
Created September 5, 2011 09:44
投稿、カスタム投稿、ページに応じてそれぞれのカテゴリ(カスタム分類)を表示。ページはその他扱い。
<?php
$data['url'] = get_bloginfo('url');
$data['temp_url'] = get_bloginfo('template_directory');
if($post->post_type == 'knowhow'){
$tax_type = current( get_the_terms( $post->ID, 'type' ) );
$tax = esc_attr($tax_type->slug);
if($tax == 'type_shiminuki'){
echo '<a href="' . $data['url'] . '/type/type_shiminuki"><img src="' . $data['temp_url'] . '/img/blog/cat_shiminuki.jpg" /></a>';
}elseif($tax == 'type_bag'){
echo '<a href="' . $data['url'] . '/type/type_bag"><img src="' . $data['temp_url'] . '/img/blog/cat_bag.jpg" /></a>';