wordpress: なおとのサイト制作ででたごみ
ドラマー(ドラムを叩く人)のサイトをWordpressで作ってる。
Wordpress、素晴らしいよね。ずっと以前、「MovableType vs Wordpress」みたいなことが語られていたとき、ただ当時、仕事でMovableTypeを使用していたという理由だけでMovableTypeを支持していたんだけど。今やWordpressが何の疑いもなく導入できるよね。別に細かい事情を知っているわけじゃないんだけどさ。
管理画面が最高だよ!小さなデータの書き換えにはajaxを使用して、扱っていてとても気持ちがいいね。
また、優れたプラグインの数々。今回見つけたec3_get_events() | Event Calendarは、友人のサイトに必要な「演奏スケジュール」機能を追加するのに必要なこと全てを提供してくれて、ほんとにありがたかったよ。
でも悲しいこともちょっとはある。ec3_get_events() | Event Calendarを見つけるまで、書いていたコードが全て必要なくなってしまった。つくづく、検索力って大切だよね。
私自身のメモリアル用に、いつかこの苦労を笑える日がくるためにコードを残しておくことにするよ。早い話、作業で出たごみを貧乏性で遺しておくわけだよね。
感謝したいエントリー
- [WP]カスタムフィールドの値で記事を並び替える – WebTecNote
- Loading...
- PHP: array_multisort - Manual
- http://www.bizmemowp.com/wordpress-biz170
<?php if ( have_posts() ) : $schedule_posts = array(); while ( have_posts() ) : the_post(); if (in_category('schedule')) : $c = get_post_custom(); $schedule_posts[] = array( 'link' => get_permalink(), 'title'=> get_the_title(), 'date' => $c['date_start'][0] ); endif; endwhile; asort($schedule_posts); // 直近のスケジュール2件を出力 foreach ($schedule_posts as $key => $val) { echo "<strong sty>$key = $val</strong><br />"; } for ($i=0;$i<2;$i++) : ?> <!-- <li><a href="#"><span><?php echo $c['date_start'][0]?></span><strong><?php the_title(); ?></strong></a></li> --> <?php endfor; endif; ?> $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC limit 10", ARRAY_A); echo $posts[0]['post_title'] /* スケジュール - イベント日付順にソートしてイベント一覧を返す */ function get_schedule_posts($count = 2){ if ( have_posts() ) : while ( have_posts() ) : the_post(); if (in_category('schedule')) : $c = get_post_custom(); $schedule_posts[] = array( 'link' => get_permalink(), 'title' => mb_strimwidth(get_the_title(),0,18), 'edate' => $c['date_start'][0] ); endif; endwhile; foreach ($schedule_posts as $key => $row) { $edate[$key] = $row['edate']; } array_multisort($edate, SORT_DESC, $schedule_posts); // 直近のスケジュール2件を出力 for ($i=0;$i<2;$i++) : echo "<li><a href=".$schedule_posts[$key]['link']."><span>".$schedule_posts[$key]['edate']."</span><strong>".$schedule_posts[$key]['title']."</strong></a></li>"; endfor; endif; } // 管理画面でdatepicker function my_styles(){ wp_enqueue_style('my-jquery-ui', get_bloginfo('template_url') . '/jquery-ui-1.8.6.custom.css', array(), '1.8.6', 'all'); } add_action('admin_print_styles', 'my_styles'); function my_scripts(){ wp_enqueue_script('my-jquery', get_bloginfo('template_url') . '/javascripts/jquery.js', array('jquery'), '1.4.4', true); wp_enqueue_script('my-jquery-ui', get_bloginfo('template_url') . '/javascripts/jquery-ui-1.8.6.custom.min.js', array('jquery'), '1.8.6', true); wp_enqueue_script('my-jquery-localize', get_bloginfo('template_url') . '/javascripts/jquery.ui.datepicker-ja.js', array('my-jquery-ui'), '1.8.6', true); wp_enqueue_script('my-admin-script', get_bloginfo('template_url') . '/javascripts/admin-script.js', array('my-jquery-ui'), false, true); } add_action('admin_print_scripts', 'my_scripts');//headにscript等を追加 function my_meta_date_box(){ add_meta_box('my_meta_date', '臨時休業設定', 'my_meta_date_html', 'post', 'normal', 'high'); } function my_meta_date_html($post, $box){ echo '<input type="hidden" name="my_meta_nonce" id="my_meta_nonce" value="'.wp_create_nonce('my_meta_date').'" />'; echo '<label for="date_start">イベント開始日時・・・</label>'; echo '<input class="datepicker" type="text" name="date_start" value="'. get_post_meta($post->ID, 'date_start', true) .'" size="25" />'; echo '<a class="clear_date" href="#date_start">クリア</a>'; /* echo '<span> 〜 </span><label for="date_end">終了日</label>'; echo '<input class="datepicker" type="text" name="date_end" value="'. get_post_meta($post->ID, 'date_end', true) .'" size="25" />'; echo '<a class="clear_date" href="#date_end">クリア</a>'; */ } function my_meta_date_update($post_id){ if(!wp_verify_nonce( $_POST['my_meta_nonce'], 'my_meta_date')) return $post_id; if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; if('post' == $_POST['post_type']){ if(!current_user_can('edit_post', $post_id)) return $post_id; }else{ return $post_id; } $date_start = $_POST['date_start']; if($date_start == '') $date_start = $_POST['date_end']; if($date_start == '') delete_post_meta($post_id, 'date_start'); else update_post_meta($post_id, 'date_start', $date_start); /* $date_end = $_POST['date_end']; if($date_end == '') $date_end = $date_start; if($date_end == '') delete_post_meta($post_id, 'date_end'); else update_post_meta($post_id, 'date_end', $date_end); */ } add_action('admin_menu', 'my_meta_date_box'); add_action('save_post', 'my_meta_date_update');