ブラウザの印刷時に一時的にレイアウトを変える

ブラウザの印刷機能で、表示画面を印刷するときに印刷用にjavascriptで一時的にレイアウトを変えるために

WindowEventHandlers.onbeforeprint – Web API Interfaces | MDN

を使ってみました

  function shrink() {
    $('#grid').setGridWidth(900);
  }
  window.onbeforeprint = shrink
  function revertback() {
    $('#grid').setGridWidth(1200);
  }
  window.onafterprint = revertback

メソッドは適当ですが、印刷前に onbeforeprint を呼んで幅を狭めて
印刷後に onafterprint に幅を戻してみました

javascriptをDOMを動的に書いて、CSSでの制御がつらいときに使いました

phpのDateTime型は例外をスローする

phpで日付を扱うときに DateTime を使ったりします

echo $date->format(‘Y-m-d’);

    $date = new DateTime('2015-04-01');
    echo $date->format('Y-m-d');

DateTimeに日付を渡して表示したりできます
日付以外を渡すとExceptionエラーが発生するので

try {
    $date = new DateTime('日付以外の文字');
} catch (Exception $e) {
     // 日付型の指定でない
     echo $e->getMessage();
}    

try catchで例外を受け取って処理しとくといいです

rmコマンドでハイフン始まりのファイルが消せない

Ubuntuで

-,trail:-,extends:

というなぞのファイルができてました

消そうとコマンドを

$ rm -,trail:-,extends:
rm: 無効なオプション — ‘,’
Try ‘rm ./-,trail:-,extends:’ to remove the file `-,trail:-,extends:’.
Try ‘rm –help’ for more information.

とエラーでした
いわれたとおり rm –help を見るとハイフン2つをつけるか、./ をつけるかで消せる

$ rm — -,trail:-,extends:
もしくは
$ rm ./-,trail:-,extends:

これで消せました

WordPressにTwenty Fifteenの子テーマを作って適用してみた

WordPressにTwenty Fifteenの子テーマを適用してみました
以前はTwenty Elevenの子テーマをつくっていたので、今回も子テーマを用意します

普通にWordpressをアップデートしてけば、Twenty Fifteenがあるのでインストールは終わっています

以前は

WordPressにシェアボタンを用意する過程を公開 | bgbgbg
WordPressの子テーマ用にPHPを変更する | bgbgbg

な感じで用意したので、手順はほぼ同じです

子テーマ – WordPress Codex 日本語版
を見ながら、子テーマを用意します

WordPressのインストールディレクトリへ移動して

mkdir wp-content/themes/twentyfifteen-child
touch wp-content/themes/twentyfifteen-child/style.css
touch wp-content/themes/twentyfifteen-child/function.php

style.cssの記載をします(最低限)

/*
Theme Name: Twenty Fifteen child
Template: twentyfifteen 
*/

cssはfunction.phpで読み込むようになりました

<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}       

add_action( 'wp_enqueue_scripts', 'theme_enqueue_fontawesome' );
function theme_enqueue_fontawesome() {
    wp_enqueue_style( 'parent-style', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
}                      

そしたらボタンを画面に出すのに、今回はcontent.phpにしました
子テーマへコピー

cp wp-content/themes/twentyfifteen/content.php wp-content/themes/twentyfifteen-child/content.php

で追記

/* 省略 */
        <div class="entry-content">
                /* 省略 */

                <!-- refference: http://tsuchiyashutaro.com/archives/2992 -->
                <ul class="share_btn">
                <li>
                <a class="facebook_btn"
                href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>&t=<?php the_title(); ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;">
                <i class="fa fa-facebook social_icon"></i>share</a>
                </li>
                <li><a class="twitter_btn" href="http://twitter.com/share?text=<?php the_title(); ?>&url=<?php the_permalink(); ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;">
                <i class="fa fa-twitter social_icon"></i>tweet</a>
                </li>
                <li><a class="hatebu_btn" href="http://b.hatena.ne.jp/add?mode=confirm&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"><i class="fa fa-hatena social_icon"></i><span class="hatebu_chara">はてブ<span></a></li>
                </ul>
                <!-- refference end -->
        </div><!-- .entry-content -->
/* 省略 */

でできあがりです