ユーザテーブルにカラムを追加する方法
wordpressのユーザ情報(ユーザテーブル)にカラムを追加するには以下の手順を実行する
functions.phpに以下を追加する
1.カラムの追加
function add_users_columns( $columns ) {
$columns['point_hamalove'] = 'ハマラブポイント';
return $columns;
}
add_filter( 'manage_users_columns' , 'add_users_columns' );
2.一覧画面に表示
function add_users_custom_column( $dummy, $column, $user_id ) {
if ( $column == 'point_hamalove' ) {
$user_info = get_userdata($user_id);
return $user_info->point_hamalove;
}
}
add_filter( 'manage_users_custom_column', 'add_users_custom_column', 10, 3 );
3.編集画面に表示
function add_user_custom_meta( $columns ){
$columns[ 'point_hamalove' ] = 'ハマラブポイント';
return $columns;
}
add_action( 'user_contactmethods' , 'add_user_custom_meta' );
4.新規登録画面に追加
function set_user_new_custom_profile(){
echo '<table class="form-table"><tr class="form-field"><th><label for="pr">ハマラブポイント</label></th><td><input type="text" name="point_hamalove" /></td></tr></table>';
}
add_action( 'user_new_form' , 'set_user_new_custom_profile' );
<div>で要素を並べる方法(要素の幅をそろえたい場合)
要素の横幅をそろえたいときは display : flex を使う
<style>
.d_contents2 {
display: flex;
flex-wrap: wrap;
width: 100%;
}
.d_item2 {
width: calc(100% / 3);
padding: 0px 0px;
text-align: center;
}
</style>
<div>ポイント履歴</div>
<div class="d_contents2">
<div class=d_item2>日付</div>
<div class=d_item2>摘要</div>
<div class=d_item2>ポイント</div>
<div class=d_item2>2022年1月15日(土)</div>
<div class=d_item2>新横浜駅・太尾堤緑道・大倉山梅林・大倉山駅ハイキングの下見</div>
<div class=d_item2>1</div>
<div class=d_item2>2022年3月19日(土)</div>
<div class=d_item2>銀河探検隊(現地調査)</div>
<div class=d_item2>1000</div>
</div>
<div>で要素を並べる方法(要素の横幅がまちまちの場合)
要素の横の大きさがまちまちの場合は float を使うとよい
<style>
.d_contents {
overflow: hidden;
}
.d_item {
float: left;
padding: 20px 30px;
text-align: center;
}
</style>
<div class="d_contents">
<div class=d_item>ポイント残高</div>
<div class=d_item>1001</div>
<div class=d_item>ポイント</div>
</div>
投稿されたコメントの認証について
投稿されたこめんとは「認証待ち」になる。
この設定は、
「設定」→「ディスカッション」
にて、
- コメントの手動承認を必須にする
- すでに承認されたコメントの投稿者のコメントを許可し、それ以外のコメントを承認待ちにする
- 2個以上のリンクを含んでいる場合は承認待ちにする
などの設定にしたがって動作する。
コメントの昇順降順も指定できる。
抜粋用の文章入力をする方法
the_excerpt()で取得する文字列を、本文から110文字ではなく、任意の文章にするため、記事の入力ページに抜粋用の文章入力エリアを表示させる。その為にはfunction.phpに次の1行を追記する。
add_post_type_support('page','excerpt');
固定ページの親ページにて、子ページの一覧を出力する方法
親ページの用意
固定ページで親ページをつくる。slugをたとえばeventlistとする
page.phpをコピーしてpage-eventlist.phpをつくる。
slugを指定するとそのページのテンプレートはpage-[入力されたslug].phpとなる
親ページの記述
一覧表示ページ(親ページ)にて、子ページを取得してwhileのループでタイトルに<a>タグをつけて、本文から抜粋(defaultは先頭110文字)を取得して表示する。
the_title():タイトル表示
the_permalink():リンク表示
get_the_excerpt():本文取得
<ul> <li> |
functions.phpに関数追加
サブクエリで子供たちを取得する関数
子ページの情報を取得するクエリを発行し、取得したwpオブジェクトをreturnする
get_the_ID():現在表示中のページのIDを取得
posts_per_page:取得するページ数、-1なら全てのページ
function damien_get_child_pages($number = -1,$specified_id = null){ if(isset($specified_id)): $parent_id=$specified_id; else: $parent_id=get_the_ID(); endif; $args=array( 'posts_per_page'=> $number, 'post_type'=>'page', 'orderby'=>'menu_order', 'order'=>'ASC', 'post_parent'=>$parent_id, ); $child_pages = new WP_Query($args); return $child_pages; } |