WordPressのコメント投稿後にthanksページへリダイレクトさせる方法
タイトルの通りです。。。
comment_post_redirectをフックに使います。
<? php function custom_comment_post_redirect( $location ) { $redirect_to = get_site_url( null, '/thanks' ); return $redirect_to; } add_filter( 'comment_post_redirect', 'custom_comment_post_redirect' ); ?>
WordPressのコメントに項目を追加する方法
WordPressに掲示板の機能をコメント機能で対応しようとすると、項目が足りなっ!!
って事がありますよね〜
その時に項目を追加する方法をWordPantsの記事で発見したので、コメントタイトルを追加する方法を備忘的にまとめときます。
※WordPantsってネーミングが秀逸w
(1)コメントタイトル欄を追加
<? php <td align="left" bgcolor="#FEB3CA"><span class="style1">書き込みタイトル<br> <span class="style3">※最大30文字</span></span></td> <td align="left" bgcolor="#FFFFFF"> <input id="comment-title" name="comment-title" type="TEXT" size=56 maxlength="30"> </td> ?>
(2)コメントタイトルの登録、更新機能を実装する
comment_post、edit_commentをフックに使う
<? php function comment_field( $comment_id ) { if ( !$comment = get_comment( $comment_id ) ) return false; $custom_key_title = 'comment-title'; $get_comment_title = esc_attr( $_POST[$custom_key_title] ); if ( '' == get_comment_meta( $comment_id, $custom_key_title ) ) { add_comment_meta( $comment_id, $custom_key_title, $get_comment_title, true ); } else if ( $get_comment_title != get_comment_meta( $comment_id, $custom_key_title ) ) { update_comment_meta( $comment_id, $custom_key_title, $get_comment_title ); } else if ( '' == $get_comment_title ) { delete_comment_meta( $comment_id, $custom_key_title ); } return false; } add_action( 'comment_post', 'comment_field' ); add_action( 'edit_comment', 'comment_field' ); ?>
(3)管理画面でコメントタイトルの修正機能を実装する。
add_meta_boxes_commentをフックに使う
<? php add_action( 'add_meta_boxes_comment', 'comment_field_box' ); function comment_field_box() { global $comment; $comment_ID = $comment->comment_ID; $custom_key = 'post_reviews_date' ; $custom_key_title = 'comment-title' ; $noncename = $custom_key . '_noncename' ; $get_comment_title = esc_attr( get_comment_meta( $comment_ID, $custom_key_title, true ) ); echo '<input type="hidden" name="' . $noncename . '" id="' . $noncename . '" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />' . "\n"; echo '<p><b><label for="comment-title">【コメントタイトル】</label></b></p><p><input id="' . $custom_key_title . '" name="' . $custom_key_title . '" type="text" value="' . $get_comment_title . '" size="56" maxlength="30"/></p>' . "\n"; } ?>
(4)管理画面のコメント一覧にコメントタイトルを追加しちゃえ〜
manage_edit-comments_columns、manage_comments_custom_columnをフックに使う
<? php function manage_comment_columns($columns) { $columns['comment-title'] = "コメントタイトル"; return $columns; } function add_comment_columns($column_name, $comment_id) { if( $column_name == 'comment-title' ) { $comment_title = get_comment_meta( $comment_id, 'comment-title', true ); echo attribute_escape($comment_title); } } add_filter( 'manage_edit-comments_columns', 'manage_comment_columns' ); add_action( 'manage_comments_custom_column', 'add_comment_columns',null, 2); ?>
WordPressにGoogleAnalyticsを導入する(PC、携帯対応)
WordPressにGoogleAnalyticsを導入する方法です。
PC用、携帯用それぞれプラグインを導入し対応します。
PC対応(Google Analyticator)
(1)プラグインの新規追加で「Google Analyticator」を追加
(2)メニューの日本語化対応
・正常動作を確認し、ここのサイトから日本語化ファイルをダウンロード
・解凍したファイルをplugins/google-analyticator/localization 配下に設置
携帯対応(ks-google-analytics.php)
(1)Google Analyticsのサイトでga.phpと携帯用のトラッキングコードを発行する。
(2)ここのサイトからソースをダウンロードする。
(3)ダウンロードしたソースコードのGA_ACCOUNTをGoogle Analyticsのサイトで発行した携帯用トラッキングコードの
ACCOUNTキーを編集して、ks-google-analytics.phpという名前で保存する。
(4)携帯ページのfooter.phpに< ?php ks_wp_footer(); ? > を追記する。
(5)それぞれのファイルをWordPressのフォルダに設置する。
ga.php⇒ドキュメントルート(wordpress/ga.phpなど)
ks-google-analytics.php⇒プラグインフォルダ(plugins/ks-google-analytics.php)
footer.php⇒ktay-themeseフォルダ(ktai/footer.php)
WordPressのカスタム投稿タイプの一覧表示に項目を追加する方法
WordPressのカスタム投稿タイプの管理一覧画面に項目を追加する方法です。
管理一覧画面に項目を表示するには「manage_posts_custom_column」をフックに
対応します。
functions.phpに下記の内容を追記
<? php function manage_hogehoge_columns($columns) { //管理画面一覧のタイトルに項目追加 $columns['hogehoge'] = "ほげほげ"; //タイトル追加 return $columns; } function add_hogehoge_columns($column_name, $post_id) { if( $column_name == 'hogehoge' ) { $hogehoge = get_post_meta( $post_id, '_hogehoge', true ); echo attribute_escape($hogehoge); } } add_filter( 'manage_edit-hogehoge_columns', 'manage_hogehoge_columns' ); add_action( 'manage_posts_custom_column', 'add_hogehoge_columns',null, 2); ?>
WordPressでコメント投稿後のページを指定する
WordPressのコメント機能を使った掲示板(BBS)を作成した時のThanksページ作成方法です。
コメント投稿のcomment_post_redirectをフックにリダイレクト先を指定してやれば
できるみたいです。
functions.phpに下記の内容を追記
<?php //コメント投稿後にthanksページへリダイレクト設定 function custom_comment_post_redirect( $location ) { $redirect_to = get_site_url( null, '/bbs/thanks' ); //リダイレクト先を指定 return $redirect_to; } add_filter( 'comment_post_redirect', 'custom_comment_post_redirect' ); ?>
■
ASCIIcastのRails3.1Overviewを見ながらお勉強です。
Gemfileの内容について
source 'http://rubygems.org' gem 'rails', '3.1.0.rc4' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' # Asset template engines # CSSをRubyっぽく書ける gem 'sass-rails', "~> 3.1.0.rc" # JavascriptをRubyっぽく書ける gem 'coffee-script' gem 'uglifier' # JQueryに変わった gem 'jquery-rails' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger # gem 'ruby-debug19', :require => 'ruby-debug' group :test do # Pretty printed test output gem 'turn', :require => false end #下記2行を追加 gem 'execjs' gem 'therubyracer'
Rails3.0Migrationとの違い
migrateのself.upとself.downがchangeに変わってる。
リモート管理の為の接続ポート一覧
Windows端末のリモート管理の為の接続ポート(TCP)一覧
リモートデスクトップ:3389
Rsync:873
VNC:5900