LoginSignup
0
2

More than 5 years have passed since last update.

よく使ってるワードプレスの命令

Posted at

にゃんこさまが大好きすぎて早く帰りたいぬこっぺぱんです。
最近、ワードプレス案件が増えて尚且、「これどうやって表現するんだっけ・・・」となりすぎるので、自分なりメモ。
みかんなので、どんどん追記していきます。

初期設定時

カスタム投稿タイプ

テーマにある function.php の何処かにフィルターアクションを設置。

function.php

<?php
    // 投稿タイプを新規で追加した場合、WPが正しくURLを認識しなくなるためリセットする
    global $wp_rewrite;
    $wp_rewrite->flush_rules();

    function create_post_type() {
    // カスタム投稿
    register_post_type( 'custom',
        array(
            'labels' => array( // ラベル
                'name' => 'カスタム投稿',
                'singular_name' => 'カスタム投稿',
                'add_new' => '新規追加',
                'add_new_item' => '新規カスタム投稿を追加',
                'edit_item' => 'カスタム投稿の編集',
                'new_item' => '新規カスタム投稿を追加',
                'search_items' => 'カスタム投稿を検索',
                'view_item' => 'カスタム投稿を表示',
            ),
            'public' => true, // 投稿タイプをパブリックにするか
            'has_archive' => true, // アーカイブを有効にするか
            'supports' => array(
                'title', // 記事タイトル
                'editor', // 記事本文
                'thumbnail' // サムネイル
            ),
            'menu_icon' => 'dashicons-edit', // メニューアイコン
            'publicly_queryable' => true,
            'rewrite' => true,
        )
    );
    add_post_type_support( 'custom', 'revisions' ); // リビジョンに対応させる場合

    // カスタム投稿カテゴリー
    register_taxonomy(
        'custom-cat',
        array( 'custom' ),
        array(
            'label'             => 'カテゴリー', //表示名
            'show_ui'           => true, //管理画面に表示するか
            'show_admin_column' => true, //管理画面の一覧に表示するか
            'show_in_nav_menus' => true, //カスタムメニューの作成画面で表示するか
            'hierarchical'      => true, //階層構造を持たせるか(持たせるとカテゴリー扱い)
        )
    );
}
add_action( 'init', 'create_post_type' );

さらなる項目を追加したい場合は、create_post_type()内にある、register_post_typeregister_taxonomyを1セットで設定していく。

register_post_type()

supportsは記事投稿する際に、編集画面に表示される項目群の設定になる。
表記している内容だと

項目 内容
title 記事タイトル
editor Widget
thumdnail アイキャッチ

上記のようなものになる。

menu_iconに設定するメニューアイコンは、公式に用意されているのでそこから選択する。
WordPress Developer Resources: Dashicons

細かい設定内容に関しては、下記を参照してください。
MORILOG カスタム投稿タイプの設定
WORDPRESS Codex日本語版

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2