• Home
  • サイトマップ
Blue Orange Green Pink Purple

Archive for 4 月, 2009

You can use the search form below to go through the content and find a specific post or page:

4 月 10

カスタムフィールドの記事内での表示方法

カスタムフィールドの基本的な使い方は、WordPress公式ドキュメントを参照

記事中に全てのカスタムフィールドのメタデータを表示する場合は、WordPressループ内に

<?php the_meta(); ?>

を記述すれば、順不同リスト形式で表示できます。

特定キーのメタデータのみを表示したい場合は get_post_meta() 関数を使い

<?php echo get_post_meta($post->ID,'公開希望日',TRUE); ?>

でループ内に表示できます。
指定するキーは日本語もOKです。

ひとつのキーに対して、複数のメタデータがある場合、上述だと表示出来ないので、その方法を。
$single が TRUE だと、一つ目のメタデータのみしか文字列で取得出来ないので、FALSEを指定するんですが、この場合配列で返ってきます。この配列要素を文字列で連結するため implode()関数を使います。但しメタデータが空の場合、エラーになるのでそれを回避。

<?php
$stuff = get_post_meta($post->ID,'担当',FALSE); // $stuff に キー「担当」のメタデータ配列を格納
if($stuff != ""){ // メタデータ配列が空でない場合
echo implode(",", $stuff); // カンマで連結して文字列表示 implode("区切り文字",配列)
}
?>

(PHPは詳しくないので分かりませんが、他にも近い関数があるようですし、もっとスマートな記述はあると思います)

4 月 07

Comment Notifier カスタマイズ

新規コメント(承認待ち、公開)時のメール通知プラグイン「Comment Notifier」のメール通知の内容をカスタマイズ。

新規コメント通知のメールフォーマットを
From:(コメント投稿者)(コメント投稿者E-mail)
Subject:(ブログ名)返信:(記事タイトル)
Body:(コメント投稿者)さんより
   (記事タイトル)に返信がありました

   返信内容:(コメント内容)
   返信内容を確認:(コメントURL)
にしたいので、

comments-notifier.phpの232〜246行目

$notify_message  = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";

から

$subject = apply_filters('comment_notification_subject', $subject, $comment_id);
$message_headers = "MIME-Version: 1.0\n"
. "$from\n"

までを

$notify_message  = sprintf( __('%1$s さんより'), $comment->comment_author ) . "\r\n";
$notify_message .= sprintf( __('「%1$s」に返信がありました'), $post->post_title ) . "\r\n\r\n";
$notify_message .= __('返信内容:') . "\r\n" . $comment->comment_content . "\r\n\r\n";
$notify_message .= __('返信内容を確認:') . "\r\n";
$subject = sprintf( __('[%1$s] 返信:%2$s'), $blogname, $post->post_title );
$notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
$notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id);
$subject = apply_filters('comment_notification_subject', $subject, $comment_id);
$message_headers = "MIME-Version: 1.0\n"
. "From: $comment->comment_author <$comment->comment_author_email> \n"

に差し替え

WordPress備忘ログ

  • カテゴリー
    • Mac (1)
    • WordPress (14)
    • WordPress MU (7)
    • カスタマイズ (13)
    • テーマ (1)
    • プラグイン (4)
    • 京都 (1)
  • 最近の投稿
    • Mac OS X環境移行
    • カスタムフィールドの記事内での表示方法
    • Comment Notifier カスタマイズ
    • WordPress(MU) コメント通知のカスタマイズ
    • Quick Comments (コメント投稿強化&コメント通知)
    • Subscribe2 カスタマイズ
    • XREA で WordPress アップロード機能を使う
  • タグ
    新規タグの追加
  • アーカイブ
  • Archives
    • 2010 年 7 月
    • 2009 年 4 月
    • 2009 年 3 月
    • 2009 年 2 月
  • Search






  • Home
  • サイトマップ

© Copyright WordPress備忘ログ. All rights reserved.
Designed by FTL Wordpress Themes brought to you by Smashing Magazine

Back to Top