回答編集履歴
1
記入ミス
answer
CHANGED
@@ -1,94 +1,1 @@
|
|
1
|
-
### ターム別一覧記事の作成(自分用)
|
2
|
-
|
3
|
-
|
4
|
-
■■プラグイン「Custom Post Type Permalinks」を使用した方法
|
5
|
-
プラグイン有効化→「カスタマイズされたカスタムタクソノミーのパーマリンクを使用する。」にチェック。
|
6
|
-
|
7
|
-
### functions.php
|
8
|
-
|
9
|
-
```php
|
10
|
-
<?php
|
11
|
-
/* カスタム投稿タイプを設定 */
|
12
|
-
function my_custom_post_topics() {
|
13
|
-
$labels = array(
|
14
|
-
'name' => _x('トピックス', 'post type general name'),
|
15
|
-
'singular_name' => _x('トピックス', 'post type singular name'),
|
16
|
-
'add_new' => _x('トピックスを追加', 'topics'),
|
17
|
-
'add_new_item' => __('トピックスを追加'),
|
18
|
-
'edit_item' => __('トピックスを編集'),
|
19
|
-
'new_item' => __('トピックス'),
|
20
|
-
'view_item' => __('トピックスを表示'),
|
21
|
-
'search_items' => __('トピックスを探す'),
|
22
|
-
'not_found' => __('トピックスはありません'),
|
23
|
-
'not_found_in_trash' => __('ゴミ箱にトピックスはありません'),
|
24
|
-
'parent_item_colon' => ''
|
25
|
-
);
|
26
|
-
$args = array(
|
27
|
-
'labels' => $labels,
|
28
|
-
'public' => true,
|
29
|
-
'publicly_queryable' => true,
|
30
|
-
'show_ui' => true,
|
31
|
-
'query_var' => true,
|
32
|
-
'rewrite' => true,
|
33
|
-
'capability_type' => 'post',
|
34
|
-
'hierarchical' => false,
|
35
|
-
'menu_position' => 5,
|
36
|
-
'has_archive' => true,
|
37
|
-
//'rewrite' => array( 'slug' => 'topics'),//変更前
|
38
|
-
'supports' => array('title','editor','author','thumbnail','revisions', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'page-attributes')
|
39
|
-
);
|
40
|
-
|
1
|
+
--記入ミス--------------------------------------
|
41
|
-
|
42
|
-
$args = array(
|
43
|
-
'label' => 'トピックスカテゴリー', /* ダッシュボードに表示する名前 */
|
44
|
-
'labels' => array(
|
45
|
-
'all_items' => 'トピックスカテゴリー一覧',
|
46
|
-
'add_new_item' => 'トピックスカテゴリーを追加'
|
47
|
-
),
|
48
|
-
'hierarchical' => true, /* カテゴリーの場合はtrue */
|
49
|
-
'show_ui' => true,
|
50
|
-
'show_in_nav_menus' => true,
|
51
|
-
'query_var' => true,
|
52
|
-
'rewrite' => true, /* パーマリンクのリライトの許可。 追記*/
|
53
|
-
'singular_label' => 'トピックスカテゴリー',
|
54
|
-
/*'rewrite' => array(
|
55
|
-
'slug' => 'topics',//★URLでtopics_catと表記されるのをtopicsに変更
|
56
|
-
'hierarchical' => true //★true にすると階層化したURLを使用可能にする
|
57
|
-
)*/ //変更前
|
58
|
-
);
|
59
|
-
register_taxonomy(
|
60
|
-
'topics_cat', /* 分類名 */
|
61
|
-
'topics', /* このタクソノミーを使う投稿タイプ */
|
62
|
-
$args
|
63
|
-
);
|
64
|
-
}
|
65
|
-
add_action('init', 'my_custom_post_topics');
|
66
|
-
|
67
|
-
//以下 追記
|
68
|
-
function rewrite_topics_category() {
|
69
|
-
$args = get_taxonomy( 'topics_cat' );
|
70
|
-
$args->show_admin_column = true;
|
71
|
-
$args->rewrite['slug'] = 'topics';
|
72
|
-
$args->rewrite['with_front'] = false;
|
73
|
-
register_taxonomy( 'topics_cat', 'topics', (array) $args );
|
74
|
-
}
|
75
|
-
add_action( 'init', 'rewrite_topics_category', 11 );
|
76
|
-
|
77
|
-
|
78
|
-
// カスタム投稿とカスタムタクソノミーを同一スラッグ(news)にした際に、ページネーションででる404エラーの回避。 変更前
|
79
|
-
//add_rewrite_rule('topics/([^/]+)/page/([0-9]+)/?$', 'index.php?topics_cat=$matches[1]&paged=$matches[2]', 'top');
|
80
|
-
?>
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
```
|
85
|
-
|
86
|
-
### その他必要なテンプレ
|
87
|
-
|
88
|
-
・
|
89
|
-
**archive-(カスタム投稿タイプ).php** ...記事一覧ページ
|
90
|
-
・
|
91
|
-
**taxonomy-(カスタムタクソノミー)-(ターム名).php** ...ターム別一覧ページ
|
92
|
-
・
|
93
|
-
**single-(カスタム投稿タイプ).php** ...投稿ページ
|
94
|
-
・
|