フォルダ以下を再帰的にgrep検索する方法
// 全てのファイルからhogehogeを検索 find . -name '*' | xargs grep hogehoge // 全てのphpファイルからhogehogeを検索 find . -name '*.php' | xargs grep hogehoge
参照元:http://shoulder.jp/archives/009306.php
尚、検索対象がsvn管理下にある場合余計なファイル「.svn/」以下のものも検索として引っかかってきてしまうので
それを避ける為には、以前のエントリを参照のこと。
指定文字数で文字を切る便利関数を追加する
今wordpressのテーマのカスタマイズ(オリジナルテーマをフルスクラッチで作る)をやっていて、自分用のメモ。
smartyやTTなどのテンプレートエンジンではよくある指定文字数で文字を切って最後に「...」を付けるtruncateみたいな便利関数です。
smartyのそれを、ほぼそのまま移植。
追記場所
/wp-content/themes/テーマ名/function.php
上記のファイルに以下を追加
function truncate($str, $limit = 80, $etc = '...') { if($limit == 0) {return '';} $str = strip_tags($str); if(mb_strlen($str) > $limit) { return mb_substr($str, 0, $limit).$etc; } else { return $str; } }
テンプレート側からの呼び出し
<?php echo truncate(get_the_excerpt(), 100); ?>
mb_strlen, mb_substr を使っているので日本語も文字化け無く通るはずです。
参考にさせてもらったurl: http://c-brains.jp/blog/wsg/07/06/14-160910.php
エントリの末端ジャンルを返す便利関数
この関数はループ中で使うことを前提としてる。
function cat_last_child(){ $cats = get_the_category(); $current = ''; foreach($cats as $cat){ if(!$current || cat_is_ancestor_of($current, $cat)) { $current = $cat; } } return $current; }
上記を、function.phpへ追加する。
オブジェクトとして返しているので、テンプレ側ではecho などで出力する
<?php $my_cat = cat_last_child(); echo $my_cat->name; // 末端のカテゴリ名 echo $my_cat->cat_ID; // 末端のカテゴリID ?>
Aカテゴリーが、Bカテゴリーの祖先にあたるかどうかを返してくれるcat_is_ancestor_ofという関数
http://ja.forums.wordpress.org/topic/1290?replies=5 より。
VPSサーバを借りてみるテスト
お名前.comにしてみるテスト。
PS3+Apple Wireless Keyboard US配列での入力モードの切替
option + ~(チルダ) で日本語・英語の切替
svn log を日付指定で
svn log -r {2008-01-01}:HEAD /dir
trunc/test と branches/test をマージする
svn merge -r136720:136721 svn+ssh://username@xxx.jp/honkamo/branches/test
このとき、--dry-runを付けると、マージの実行テストができる。