0

wordpress 管理パネル用のカスタム画像アップローダを作成しましたが、wp_options テーブルからデータを取得する必要があります。以下の関数を書きました:

//function to get all slider images
function getSliderImages(){
    global $wpdb, $theme_shortname;
    $query = "SELECT * FROM $wpdb->options AS o1 
    WHERE o1.option_name LIKE '%".$theme_shortname."_header_image%'";
    $imgs = $wpdb->get_results($query);

    $images = array();
    //loop through images and remove unusable results
    foreach($imgs as $i){
        $id = substr($i['option_name'],0,-1);
        if(is_numeric($id)){
            $images[] = $i['option_value'];
        }
    }

    return($images);
}

フロントエンドの header.php で返された配列にアクセスするにはどうすればよいですか? この関数は現在、themes/themename/functions.php にあります

4

1 に答える 1

1

すべてのテンプレート ファイルで使用できるグローバル関数を宣言しています。<?php $images = getSliderImages(); ?>どのテンプレートでも簡単に使用できます。

于 2012-05-10T11:25:58.957 に答える