blog.knym.net | I'm searching something to change my life.

Posts Tagged "snippet"

wordpressのtheme内で、トップページかどうかの判別

下記でややこしいことしてるんだけど、、、
is_front_page()でトップページかチェックできる。


$wp_queryを呼び出すタイミングが遅いとエントリの一覧表示後などには、
表示されているページと違う内容が代入されているので、
wp_headを呼ぶタイミングで表示されているページのIDを取っておくようにした。


んー、説明がややこしいけど、要は、
以下のプログラムをtheme内のfunctions.phpに仕込んでおくと
トップページにだけ表示するコンテンツ内容が操作できて便利ですよという話。

Read More ›

jqueryで画像の幅を自動的にページ幅に合わせて縮小

画像がエントリ表示の幅をはみ出して表示されるのをjqueryで直してみた。


before


after

Read More ›

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などで以下のコードを入れとくと出力。

Read More ›

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
description = Just another WordPress blog

Read More ›

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";
    return $wpdb->get_results($sql);
}
via beginsprite

Read More ›

読み込んだ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) {
                trace(instance+" is Bitmap");
            }else if (instance is DisplayObjectContainer) {

Read More ›

オブジェクトが継承してるクラス名の取得

import flash.utils.describeType;


//itemという変数のクラス名をとるとき
var className:String = String(describeType(item).@name).match(/::(.*)/)[1];


flash.utilsはあなどれん。

Read More ›

 

Essentials

Meta

Pages

Categories