本日もメモ代わりに書かせていただきます。
WPの予約投稿って便利だけど、既に投稿してあるページには適応不可。
『そんな投稿しないでしょ!』
なんて言わないでくださいね・°・(ノД`)・°・
固定ページにはPHP入れまくりの場合お客様に管理画面を渡すと、めちゃくちゃに・・・;
そしてエラーに・・・;
なので、ページ風に投稿を一つ作成。
これでお客様も簡単に更新可能&PHPはこちらで管理が自分的には最適(*゚.゚)ゞ
ということで、いろいろ試しましたが、エラー連発・・・;(笑)
しかし、成功した時のあの感触は幸せですね~(●´ω`●)ゞ
忘れないようにメモメモ。
管理画面的には納得のいかないカスタマイズですが、とりあえずfunctionをいじって応急対応。
//念のため
date_default_timezone_set('Asia/Tokyo');
$fu_key = 'futureupdate';
function my_get_content(){
global $post, $fu_key;
$now = date('Y/m/d H:i');
$update = get_post_meta($post->ID, $fu_key, true);
if(!$update || ($update && $update <= $now))
//return get_the_content();
return the_content();
$args = array(
'order' => 'DESC',
'orderby' => 'ID',
'post_parent' => $post->ID,
'post_type' => 'revision',
'post_status' => 'inherit',
'meta_key' => $fu_key,
'meta_value' => $now,
'meta_compare' => '<='
);
if($revisions = get_children($args))
foreach($revisions as $revision)
return $content = apply_filters('the_content', $revision->post_content);
return 'No content.';
}
//meta_box管理画面に追加
function my_meta_futureupdate_box(){
add_meta_box('my_meta_futureupdate_box', '更新予定日時の指定',
'my_meta_futureupdate_html', 'post', 'normal', 'high');
add_meta_box('my_meta_futureupdate_box', '更新予定日時の指定',
'my_meta_futureupdate_html', 'page', 'normal', 'high');
}
function my_meta_futureupdate_html($post, $box){
global $fu_key;
$value = get_post_meta($post->ID, $fu_key, true);
if(!$value) $value = '';
echo '<input type="hidden" name="my_meta_futureupdate_nonce" id="my_meta_futureupdate_nonce"
value="'.wp_create_nonce(get_bloginfo('template_url') . $fu_key).'" />'."\n"
. '<div><label for="futureupdate">更新予定日時(YYYY/MM/DD HH:II)</label>'."\n"
. '<input type="text" name="futureupdate" value="'. $value .'" size="50" /></div>'."\n";
}
function my_meta_futureupdate_update($post_id){
global $fu_key;
if(!wp_verify_nonce( $_POST['my_meta_futureupdate_nonce'], get_bloginfo('template_url') . $fu_key)){
return $post_id;
}
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
if('page' == $_POST['post_type']){
if(!current_user_can('edit_page', $post_id))
return $post_id;
}else{
if(!current_user_can('edit_post', $post_id))
return $post_id;
}
if($parent_id = wp_is_post_revision($post_id)){
$old = get_post_meta($parent_id, $fu_key, true);
if($old)
update_metadata('post', $post_id, $fu_key, $old);
}else{
if(isset($_POST[$fu_key]))
update_metadata('post', $post_id, $fu_key, $_POST[$fu_key]);
}
}
add_action('admin_menu', 'my_meta_futureupdate_box');
add_action('save_post', 'my_meta_futureupdate_update');
PCと携帯はそれぞれのループ内conntentを書き換えで異常なく動いたけWPtouchだけ固定ページに対してエラーが発生。(謎い;)
根気強くfunction書き換えで何とか思い通りの動作を確認できました。
やっぱりWPは楽しい~(*^▽^*)
無料のCMSにしては高機能過ぎるけど、エラーは見逃せない・・・;;
WPのカスタマイズってECCUBEのSmarty関数になれてしまうと、結構忘れちゃうんですよね・・・;;
さて、今日もファイト~≧(´▽`)≦