「この記事を編集」のリンクを追加するコード

PHPコード コメントは受け付けていません。

固定ページ、シングルページの下の方に、記事を編集するためのリンクを貼っておくと、編集がラクである。

<?php edit_post_link('この記事を編集', '<p>', '</p>'); ?>

ログイン中のユーザーIDを取得する

PHPコード コメントは受け付けていません。
global $userdata;
get_currentuserinfo();
echo $userdata->ID;

get_currentuserinfo()を呼び出すと、現在のユーザーの情報が$userdataに格納され、それぞれの値がメンバー変数として取得できるようになる。

<?php global $current_user;
      get_currentuserinfo();

      echo 'Username: ' . $current_user->user_login . "\n";
      echo 'User email: ' . $current_user->user_email . "\n";
      echo 'User level: ' . $current_user->user_level . "\n";
      echo 'User first name: ' . $current_user->user_firstname . "\n";
      echo 'User last name: ' . $current_user->user_lastname . "\n";
      echo 'User display name: ' . $current_user->display_name . "\n";
      echo 'User ID: ' . $current_user->ID . "\n";
?>

日付の形式について

PHPコード コメントは受け付けていません。

日付を表示するときには、the_time()を使う。

<?php the_time('Y/m/d'); ?>
‘Y年m月d日(D)’ 2009年09月09日(木)
‘Y/m/d’ 2009/09/09
‘Y年n月j日(D)’ 2009年9月9日(木)
‘Y/n/j’ 2009/9/9
‘Y年m月d日(D)h時i分s秒’ 2009年09月09日(木)09時09分09秒
‘Y/m/d h:i:s’ 2009/09/09 09:09:09

◎年
Y:4桁
y:2桁

◎月
m:先頭にゼロがつく
n:先頭にゼロをつけない

◎日
d:先頭にゼロがつく
j:先頭にゼロをつけない

◎時
h:12 時間単位。
H:24 時間単位。

ループの基本構造

PHPコード コメントは受け付けていません。
<?php if (have_posts()) : ?>
		// 投稿一覧を表示する前の処理内容
	<?php while (have_posts()) : the_post(); ?>
		// 各投稿を表示する処理内容
	<?php endwhile; ?>
		// 投稿一覧を表示した後の処理内容
<?php else : ?>
		// 投稿が無いときの処理内容
<?php endif; ?>

エディタにボタンを追加する

プラグイン関連 コメントは受け付けていません。

投稿編集画面で、メディアボタンにオリジナルのボタンを追加し、ショートコードを記事内に挿入するようなプラグイン作成の手順。

詳しくはこちら

contactform7をカスタマイズ

プラグイン関連 コメントは受け付けていません。

お問い合わせフォームプラグイン「Contact Form 7」カスタマイズまとめ

  • 確認用にメールアドレスを2回入力させ、尚且つチェックする機能
  • 郵便番号を入力すると自動で住所が入力される機能
  • 送信後、サンキューページに転送させる
  • Google Analyticsでコンバージョン設定する

こちら

トップページに記事を1件表示する

テーマ関連 コメントは受け付けていません。
<?php
$posts = get_posts('&showposts=1');
if($posts): foreach($posts as $post): setup_postdata($post);
?>
<h2><?php the_title(); ?></h2>
<?php the_content(__('(more...)')); ?>
<?php endforeach; ?>
<?php else : endif; ?>

get_postsのパラメータに、「’category_name=whatsnew’」を入れると、カテゴリースラッグ(=whatsnew)の記事を絞ることができる。
「&showposts=10」とすると、10件表示する。

◎ 全表示する場合

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(__('(more...)')); ?>
<?php endwhile; endif; ?>

ビジュアルエディタの必要のないものを消す

管理画面 コメントは受け付けていません。
function custom_editor_settings( $initArray ){
	$initArray['theme_advanced_buttons1'] = 'bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,wp_more,|,spellchecker,fullscreen,wp_adv';
	$initArray['theme_advanced_buttons2'] = 'formatselect,underline,justifyfull,forecolor,|,pastetext,pasteword,removeformat,|,charmap,|,outdent,indent,|,undo,redo,help';
	return $initArray;
}
add_filter( 'tiny_mce_before_init', 'custom_editor_settings' );

投稿画面の要らないボックスを消す

管理画面 コメントは受け付けていません。
if (!current_user_can('edit_users')) {
  function remove_extra_meta_boxes() {
    remove_meta_box( 'categorydiv','post','side'); /* 投稿のカテゴリーフィールド */
    remove_meta_box( 'postcustom' , 'post' , 'normal' ); /* 投稿のカスタムフィールド */
    remove_meta_box( 'postcustom' , 'page' , 'normal' ); /* 固定ページのカスタムフィールド */
    remove_meta_box( 'postexcerpt' , 'post' , 'normal' ); /* 投稿の抜粋 */
    remove_meta_box( 'postexcerpt' , 'page' , 'normal' ); /* 固定ページの抜粋 */
    remove_meta_box( 'commentsdiv' , 'post' , 'normal' ); /* 投稿のコメント */
    remove_meta_box( 'commentsdiv' , 'page' , 'normal' ); /* 固定ページのコメント */
    remove_meta_box( 'tagsdiv-post_tag' , 'post' , 'side' ); /* 投稿のタグ */
    remove_meta_box( 'tagsdiv-post_tag' , 'page' , 'side' ); /* 固定ページのタグ */
    remove_meta_box( 'trackbacksdiv' , 'post' , 'normal' ); /* 投稿のトラックバック */
    remove_meta_box( 'trackbacksdiv' , 'page' , 'normal' ); /* 固定ページのトラックバック */
    remove_meta_box( 'commentstatusdiv' , 'post' , 'normal' ); /* 投稿のディスカッション */
    remove_meta_box( 'commentstatusdiv' , 'page' , 'normal' ); /* ページのディスカッション */
    remove_meta_box( 'slugdiv','post','normal'); /* 投稿のスラッグ */
    remove_meta_box( 'slugdiv','page','normal'); /* 固定ページのスラッグ */
    remove_meta_box( 'authordiv','post','normal' ); /* 投稿の作成者 */
    remove_meta_box( 'authordiv','page','normal' ); /* 固定ページの作成者 */
    remove_meta_box( 'revisionsdiv','post','normal' ); /* 投稿のリビジョン */
    remove_meta_box( 'revisionsdiv','page','normal' ); /* 固定ページのリビジョン */
    remove_meta_box( 'pageparentdiv','page','side'); /* 固定ページのページ属性 */

  }
  add_action( 'admin_menu' , 'remove_extra_meta_boxes' );
}

管理者以外には必要ないサイドバーのメニューを非表示

管理画面 コメントは受け付けていません。
if (!current_user_can('edit_users')) {
  function remove_menus () {
    global $menu;
    $restricted = array(
      __('投稿'),
      __('ツール'),
      __('コメント'),
      __('固定ページ'),
      __('メディア'),
      __('お問い合わせ'),
      __('リンク')
    );
    end ($menu);
    while (prev($menu)){
      $value = explode(' ',$menu[key($menu)][0]);
      if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
        unset($menu[key($menu)]);
      }
    }
  }
  add_action('admin_menu', 'remove_menus');
}
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS ログイン