サポート » テーマ » カスタム投稿でsingle-●●.phpが効かない

  • worksというポストタイプを用意して、そこからcategorysというカスタム分類でカテゴリ分けして記事を作っています。
    パーマリンクでカスタム構造
    url/%post_id%.html
    に変更しているのですが、先方からの要望でカスタム投稿の部分だけ
    /%categorys%/%minute%.html
    のような数字ベースに変更したいとのことだったので
    プラグインで「Custom Post Type Permalinks」を利用し、上記のように変更しました。

    すると、それまで有効だったsingle-works.phpが無視されるようになり、archive-works.phpが優先されるようになりました。(single.phpより優先)

    ちなみに下記がfunctions.phpに書いたカスタム投稿用のコードです。

    function add_works_type() {
    	$works = array(
    				   'label' => '施工事例一覧',
    				   'labels' => array(
    									 'singular_name' => '施工事例記事',
    									 'add_new_item' => '施工事例を投稿する',
    									 'add_new' => '投稿',
    									 'view_item' => '投稿を見る',
    									 'not_found' => '投稿が見つかりませんでした',
    									 'not_found_in_trash' => 'ゴミ箱に投稿はありません',
    									 'search_items' => '投稿を検索',
    									 ),
    				   'public' => true,
    				   'hierarchical' => true,
    				   'menu_position' => 5,
    				   'rewrite' => ture,
    				   'supports' => array('title','editor','thumbnail','custom-fields'),
    				   'has_archive' => true,
    			  	   'with_front' => false
    
    				   );
    	register_post_type('works' , $works);
    
    	register_taxonomy(
    		'categorys',
    		'works',
    		array(
    			  'label' => '施工カテゴリ',
    			  'hierarchical' => true,
    			  'singular_label' => '施工カテゴリ',
    			  'show_ui' => true,
    			  'public' => true
    			  )
    		);
    }
    
    add_action('init' , 'add_works_type');

    どこが問題なのでしょうか…。

  • トピック「カスタム投稿でsingle-●●.phpが効かない」には新たに返信することはできません。