blog.knym.net | I'm searching something to change my life.
wordpressのtheme内で、トップページかどうかの判別
下記でややこしいことしてるんだけど、、、
`is_front_page()`でトップページかチェックできる。
`$wp_query`を呼び出すタイミングが遅いとエントリの一覧表示後などには、
表示されているページと違う内容が代入されているので、
wp_headを呼ぶタイミングで表示されているページのIDを取っておくようにした。
んー、説明がややこしいけど、要は、
以下のプログラムをtheme内のfunctions.phpに仕込んでおくと
トップページにだけ表示するコンテンツ内容が操作できて便利ですよという話。
jqueryで画像の幅を自動的にページ幅に合わせて縮小
画像がエントリ表示の幅をはみ出して表示されるのをjqueryで直してみた。
[](/wp-content/uploads/2009/04/setentryimgwidth_before.jpg)
[](/wp-content/uploads/2009/04/setentryimgwidth_after.jpg)
wordpressでカスタムフィールドの表示
/wp-content/themes/{THEME_NAME}/functions.phpに下記のfunctionを追加
function showPostMeta($key){
global $post;
if(get_post_meta($post->ID, $key, true)){
echo get_post_meta($post->ID, $key, true);
}
}
//$keys = Array("customField1","customField2","customField3"
function hasPostMetas($keys){
foreach($keys as $key){
if(hasPostMeta($key)) return 1;
}
return 0;
}
/wp-content/themes/{THEME_NAME}/page.phpなどで以下のコードを入れとくと出力。
wordpressでthemeフォルダへのパスの取得
<img src="<?php bloginfo('template_directory');?>/images/logo.gif" alt="<?php bloginfo('name'); ?>" />
よく忘れるthemeフォルダへのパスを取る関数`bloginfo(‘template_directory’)`
`bloginfo()`でとれる値の種類は下記のとおり。
admin_email = admin@example atom_url = http://example/home/feed/atom charset = UTF-8 comments_atom_url = http://example/home/comments/feed/atom comments_rss2_url = http://example/home/comments/feed
…
wordpressで子ページのデータを取得
/wp-contents/themes/{THEME_NAME}/functions.php
に以下のように子ページのデータを取得する関数をしこんだ。
(子カテゴリーとか検索するといっぱい見つかるけど、子ページってなかなか見つからない。)
function getPageChildren($id){
global $wpdb;
$sql = "SELECT * FROM $wpdb->posts WHERE (post_type = 'page' AND post_status = 'publish') AND post_parent = $id ORDER BY menu_order ASC";
…
読み込んだswfの中のinstanceのbitmapだけに何かしたいとき~
var swf = loader.content.root as MovieClip;
checkChildren(swf);
function checkChildren(container:DisplayObjectContainer) {
for (var i:int = 0; i < container.numChildren; i++)
{
var instance:* = container.getChildAt(i);
trace(instance);
if (instance is Bitmap)…
オブジェクトが継承してるクラス名の取得
import flash.utils.describeType;
//itemという変数のクラス名をとるとき
var className:String = String(describeType(item).@name).match(/::(.*)/)[1];
flash.utilsはあなどれん。