Custom post type UI とYARPPで関連記事をカスタム投稿にも表示する方法


wordpressの関連記事を表示するプラグイン、YARPP ( Yet another related post )を追加しましたが、デフォルトだとCustom post type IU で追加したカスタム投稿タイプには関連記事が表示されないよう。(固定ページと投稿ページだけ表示できる)

 

 

どうしてもカスタム投稿タイプに関連記事を表示したかったのでやり方を調ると

 

 

 

functions.php に register_post_type を記述し、オプションに「’yarpp_support’ => true」を追加する

 

 

ということです。具体的には

 

 

1、 Custom post type UI の Manage Post Types から該当する post type の 「 Get Code 」をクリック

 

2、 表示されたコードを function.php に貼付ける

 

3、 コードの中の register_post_type の記述内に ‘yarpp_support’ => true を追記

 

 

add_action(‘init’, ‘cptui_register_my_cpt_lecture’);
function cptui_register_my_cpt_lecture() {
register_post_type(‘lecture’, array(
‘label’ => ‘麻雀教室’,
‘description’ => ”,
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘capability_type’ => ‘post’,
‘map_meta_cap’ => true,
‘hierarchical’ => false,
‘rewrite’ => array(‘slug’ => ‘lecture’, ‘with_front’ => true),
‘query_var’ => true,
‘has_archive’ => true,
‘supports’ => array(‘title’,’editor’,’excerpt’,’trackbacks’,’custom-fields’,’comments’,’revisions’,’thumbnail’,’author’,’page-attributes’,’post-formats’),
‘labels’ => array (
‘name’ => ‘麻雀教室’,
‘singular_name’ => ”,
‘menu_name’ => ‘麻雀教室’,
‘add_new’ => ‘Add 麻雀教室’,
‘add_new_item’ => ‘Add New 麻雀教室’,
‘edit’ => ‘Edit’,
‘edit_item’ => ‘Edit 麻雀教室’,
‘new_item’ => ‘New 麻雀教室’,
‘view’ => ‘View 麻雀教室’,
‘view_item’ => ‘View 麻雀教室’,
‘search_items’ => ‘Search 麻雀教室’,
‘not_found’ => ‘No 麻雀教室 Found’,
‘not_found_in_trash’ => ‘No 麻雀教室 Found in Trash’,
‘parent’ => ‘Parent 麻雀教室’,
),
‘yarpp_support’ => true
) ); }

 

参考記事:Custom Post Type UIとYARPPでカスタム投稿の関連記事を表示させる方法

Leave a Comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です