PHP:
変数に代入されている配列や値を確認する

by tomo@webys.jp on 1月 17, 2012

変数に代入されている配列や値を視覚的にわかりやすく確認するには、var_dump と pre を組み合わせて変数の内容を出力させる。

print '<pre>';
var_dump ( $example );
print '</pre>';

WordPress:
管理画面の HTML エディターを css でカスタマイズ

by tomo@webys.jp on 1月 15, 2012

管理画面の投稿・固定ページの新規追加・編集をする時に使う HTML エディターに css を適用させる。

function set_html_editor_custom_css() {
	$directory = trailingslashit(get_bloginfo('template_url'));
	$file_name = 'html_editor.css';
	$link_tag  = "<link rel=\"stylesheet\" href=\"$directory$file_name\" type=\"text/css\" media=\"screen\" />\n";
	print $link_tag;
}
add_filter('admin_head-post.php', 'set_html_editor_custom_css');
add_filter('admin_head-post-new.php', 'set_html_editor_custom_css');

WordPress:
記事の抜粋を表示させる

by tomo@webys.jp on 1月 5, 2012

記事に抜粋がある場合は抜粋を表示。
抜粋が無い場合は、more があればそれ以前を、無ければ全文を表示させる。

<?php
if(has_excerpt()) {
print the_excerpt();
} else {
the_content('read more', false);
}
?>

WordPress:
特定のページで div の css や背景画像を変える

by tomo@webys.jp on 1月 4, 2012

body に body_class、div に post_class を設定して、
目的のページに付与された class を使って css で装飾する。

<body <?php body_class(); ?>>
body.category div#header {
	background: url(../images/header_category.jpg) center top no-repeat;
}

<div> に class を設定して css で制御する。

<div <?php post_class(); ?>>
div.post-473 {
	border: solid 4px #f00;
	background: #f5f5f5;
}