[WordPress]SQLクエリを確認する
wp-config.php
define('SAVEQUERIES', true);
テンプレート内
global $wpdb; var_dump($wpdb->queries);
wp-config.php
define('SAVEQUERIES', true);
テンプレート内
global $wpdb; var_dump($wpdb->queries);
記事を表示する最小処理
<?php //各環境に合わせて修正 require( dirname( __FILE__ ) . '/../../wp-blog-header.php' ); //表示する件数 $per_page = 4; query_posts(array('posts_per_page'=>$per_page,'post_status'=>'publish')); ?> <?php if(have_posts()):while(have_posts()):the_post(); ?> <div> <?php $custom_fields = get_post_custom();?> <p><?php the_time('Y/m/d');?></p> <a href="<?php the_permalink();?>"><?php the_title();?></a> <p><?php the_content();?></p> </div> <?php endwhile;endif;?>
カスタムフィールドのファイル
$cf = get_post_meta($post->ID); $file_info = get_file_info_by_attachment_id($cf['cf_pdf'][0]);
/** * カスタムフィールドのファイル項目のIDからファイルの情報を返す * @param $attachment_id * @return string */ function get_file_info_by_attachment_id($attachment_id){ $file_url = wp_get_attachment_url($attachment_id); $upload_dir = wp_upload_dir(); $file_path = realpath($upload_dir['path'] . DIRECTORY_SEPARATOR . basename($file_url)); $result = array( 'url' => $file_url, 'path' => $file_path, 'realsize' => filesize($file_path), ); return $result; }
pagination
テーマのfunctions.phpに入れておくとよい。
function echo_pagination($params = array()){ $params = array_merge( array( 'per_page' => 6, 'link_count' => 9, 'left' => '<li><a href="%url%">◀</a></li>', 'right' => '<li><a href="%url%">▶</a></li>', 'format' => '<li><a href="%url%">%no%</a></li>', 'current_format' => '<li class="active"><a href="%url%">%no%</a></li>', ), $params ); global $paged; global $wp_query; if(empty($paged)){ $paged = 1; } $pages = $wp_query->max_num_pages; if(!$pages){ return; } if(1 < $paged){ echo preg_replace('/%url%/',get_pagenum_link($paged-1),$params['left']); } $startPageNo = max(1, $paged-floor($params['link_count']*0.5)); if($pages-$params['link_count'] < $startPageNo){ $startPageNo = $pages-$params['link_count']+1; } for($i=$startPageNo;$i<$startPageNo+$params['link_count'] && $i <= $pages;$i++){ $html = preg_replace('/%url%/',get_pagenum_link($i),$params[($i==$paged)?'current_format':'format']); echo preg_replace('/%no%/', $i, $html); } if($paged < $pages){ echo preg_replace('/%url%/',get_pagenum_link($paged+1),$params['right']); } }
404自動リダイレクトOFF
/** * 下記の機能OFF * WordPressには本来存在しないURLを指定したとしても、WordPress側で推測してユーザーがアクセスしたかったであろうURLにリダイレクトする機能 * @param $redirect_url * @return bool */ function disable_redirect_canonical($redirect_url) { if( is_404() ) { return false; } return $redirect_url; } add_filter('redirect_canonical','disable_redirect_canonical');
又は
remove_filter('template_redirect', 'redirect_canonical');
管理画面フッターWordPressリンクを非表示に
/** * 管理画面 * フッターWordPressリンクを非表示に */ function custom_admin_footer() { } add_filter('admin_footer_text', 'custom_admin_footer');
MovableType on windows xampp
■ メール送信チェックをする場合は C:\xampp\sendmail\sendmail.iniの下記の部分を設定しておく auth_username=xxxxx.xxxx auth_password=xxxxxxx ■フォルダ構成 /mt-static /cgi-bin/mt ■アクセス http://yourdomain/cgi-bin/mt/ ■ MovableTypeへサインイン ■ スタティックウェブパス /mt-static スタティックファイルパス C:\xampp\htdocs\mt_test\mt-static ■ システムチェック 次へ ■ ActivePerlインストール インストール先C:\xampp\perl C:\xampp\perlに元々あったファイルは削除 ■ コマンドプロンプト ppm Enter 設定 Areas Prefix:C:\xampp\perをチェック > ok dbd-mysql インストール ■ sendmailパス C:\xampp\sendmail\sendmail.exe ■ テンポラリーディレクトリ C:\xampp\tmp
テーマのfunctions.phpに追記する
/** * ルーティング(リライトルールの追加) * ここの設定を反映させるには下記の操作が必要 * 管理画面にて「設定」->「パーマリンク設定」->変更せずに「変更を保存」 * add_rewrite_ruleの第三引数の説明は下記 * 'top' または 'bottom'。'top' の場合、ルールは WordPressのすべての既存ルールに優先する。'bottom' の場合、ルールはすべての既存ルールがマッチしない場合に検査される。 */ function add_user_rewrite_rules() { add_rewrite_rule('^hoge/?$', 'index.php?c_controller=hoge&c_method=', 'top'); add_rewrite_rule('^hoge/([^/]*)/?$', 'index.php?c_controller=hoge&c_method=$matches[1]', 'top'); } add_action('init', 'add_user_rewrite_rules'); /** * ルーティング(リライトルールの追加)関連追加処理 * c_type,c_actionをパブリッククエリ変数として登録 * get_query_var('c_controller')で取得 */ function add_user_routes_query_vars($query_vars){ $query_vars[] = 'c_controller'; $query_vars[] = 'c_method'; return $query_vars; } add_filter('query_vars','add_user_routes_query_vars');
フィールド名を変数で指定
カスタムフィールド
CFEntryDataAddress1~CFEntryDataAddress10
CFEntryDataDetailImage1~CFEntryDataDetailImage10
を表示
<MTFor var="x" from="1" to="10"> <MTIgnore>テキストの時</MTIgnore> <MTSetVarBlock name="_CFEntryDataAddress"><MTCFEntryDataAddress<MTVar name="x">></MTSetVarBlock> <MTSetVarBlock name="_CFEntryDataAddressValue"><MTVar name="_CFEntryDataAddress" decode_html="1" mteval="1"></MTSetVarBlock> <MTIf name="_CFEntryDataAddressValue" ne=""> <MTVar name="_CFEntryDataAddressValue" encode_html="1"> </MTIf> <MTIgnore>画像の時</MTIgnore> <MTSetVarBlock name="_CFEntryDataDetailImage"><MTCFEntryDataDetailImage<MTVar name="x">></MTSetVarBlock> <MTSetVarBlock name="_CFEntryDataDetailImageValue"><MTVar name="_CFEntryDataDetailImage" decode_html="1" mteval="1"></MTSetVarBlock> <MTSetVar name="_CFEntryDataDetailImageAsset" value=""> <MTIf name="_CFEntryDataDetailImageValue" ne=""> <MTSetVarBlock name="_CFEntryDataDetailImageAsset"> <MTCFEntryDataDetailImage<MTVar name="x">Asset> <img src="<MTAssetThumbnailURL width="450" force="1">"> </MTCFEntryDataDetailImage<MTVar name="x">Asset> </MTSetVarBlock> </MTIf> <MTIf name="_CFEntryDataDetailImageAsset" ne=""> <MTVar name="_CFEntryDataDetailImageAsset" decode_html="1" mteval="1"> </MTIf> </MTFor>
カスタムフィールドのPDFへのリンク
<MTIf tag="CFEntryDataPdf"> <MTCFEntryDataPdfAsset> <a href="<MTAssetURL>" target="_blank">donwload pdf</a> </MTCFEntryDataPdfAsset> </MTIf>