サポート » 使い方全般 » カスタムタクソノミーのタームページ(一覧表示)の404エラーについて

  • 解決済 nogud

    (@nogud)


    壁にぶちあたってしまいましたので、ご教授頂けますと幸いです。

    カスタム投稿にて、下記ページを作成しております。

    ・カスタム投稿ページ(http://xxx.com/blog)
    ・タームページ(http://xxx.com/blog/css)

    パーマリンクの設定にはCustom Post Type Permalinksを使い、
    共通設定にはカスタム構造にチェックを入れ、
    http://xxx.com/%category%/%year%%monthnum%%day%%hour%%minute%%second%.htmlという風に。
    また、カスタム投稿タイプのパーマリンク設定エリアのblog欄には、
    http://xxx.com/blog/%cat%/%year%%monthnum%%day%%hour%%minute%%second%.htmlという風にしております。

    また、本来、タームページ表示時にはカスタム分類名が表示されますが、
    そこを切り取るコードをfunction.php内に書いております。(下記コード最下部)

    ソースはこちら

    register_post_type(
    	'blog',
    	array(
    		'label' => 'Blog',
    		'hierarchical' => false,
    		'query_var' => false,
    		'menu_position' => 25,
    		'has_archive' => true,
    		'rewrite' => array('slug' => 'blog'),
    		'public' => true,
    		'supports'=> array('title')
    		)
    	);
    register_taxonomy(
        'cat',
        'blog',
        array(
          'hierarchical' => true,
          'query_var' => true,
          'rewrite' => true,
          'update_count_callback' => '_update_post_term_count',
          'label' => 'カテゴリー',
          'singular_label' => 'カテゴリー',
          'show_ui' => true
        )
    );
    flush_rewrite_rules( false );
    
    //Add RewriteRule
    function my_custom_post_type_permalinks_set($termlink, $term, $taxonomy){
    	return str_replace('/'.$taxonomy.'/', '/', $termlink);
    }
    add_filter('term_link', 'my_custom_post_type_permalinks_set',11,3);

    この状態でタームページへアクセスすると404ページに飛ばされてしまいます。

    taxonomy.phpを読み込む用にするにはどのようにしたらいいでしょうか。
    ご教授の程、よろしくお願いいたします。

10件の返信を表示中 - 1 - 10件目 (全10件中)
  • モデレーター のむらけい (Kei Nomura)

    (@mypacecreator)

    いったん

    /Add RewriteRule
    function my_custom_post_type_permalinks_set($termlink, $term, $taxonomy){
    	return str_replace('/'.$taxonomy.'/', '/', $termlink);
    }
    add_filter('term_link', 'my_custom_post_type_permalinks_set',11,3);

    この部分を削除して、パーマリンクを空更新して再度アクセスしてみたらどうなるでしょう?
    Custom Post Type Permalinksプラグインを使っていたら、この記述は特に必要ない気がします。

    トピック投稿者 nogud

    (@nogud)

    返信ありがとうございます。

    ご指摘のとおり、削除後に更新でやってみましたが、404エラーとなりました。
    ちなみにblogページにてtermリストの書き出しを行い、そこにterm_linkにて飛び先を設定しております。
    削除前は http://xxx.com/blog/css という風になっていたのですが、
    削除後はhttp://xxx.com/blog/cat/css というURLが書き出されています。

    また、1つ伝え忘れていましたが、Custom Post Type Permalinksの「カスタム分類のアーカイブのパーマリンクを変更する。」にチェックを入れております。
    リンクはhttp://xxx.com/post_type/taxonomy/termに変更されてますとなっています。

    よろしくお願いいたします。

    モデレーター のむらけい (Kei Nomura)

    (@mypacecreator)

    Custom Post Type Permalinksプラグインを無効化したら404にならなかったりしますか?

    トピック投稿者 nogud

    (@nogud)

    いえ、無効にしても404でした。
    さらにパーマリンクをデフォルトにしても404でした。

    追記:個別記事はテンプレートphpがちゃんと反映されています。
    http://xxx.com/blog/css/xxx.html

    追記2:現在タームが2つあるのですが、cssは404になりますが、もう1つのwebというタームはindex.phpのテンプレが適用されるようになっていました。。

    よろしくお願いいたします。

    モデレーター のむらけい (Kei Nomura)

    (@mypacecreator)

    いえ、無効にしても404でした。
    さらにパーマリンクをデフォルトにしても404でした。

    ちなみに404になるというのは、WordPressの404.phpが適用されていますか?
    それともサーバ側の味気ないエラーページの404ですか?

    モデレーター のむらけい (Kei Nomura)

    (@mypacecreator)

    ああ!
    今気づいたんですが、タクソノミー名が’cat’じゃないですか!これですよ。

    register_taxonomyには「予約語」というのがありまして、WordPressがもともと使用しているために、バッティングしてしまうため使ってはいけない文字列というのが定められています。
    ‘cat’は、まさにそれに該当します。

    試しにblogcatとかに変えてみてください。多分いけると思います。

    トピック投稿者 nogud

    (@nogud)

    何度もありがとうございます。
    タクソノミー名を変更したところ、ついにtaxonomy.phpが表示されるようになりました!
    予約語は全く知りませんでした。非常に勉強になります。ありがとうございます。

    そこで、現状、http://xxx.com/post_type/taxonomy/term となっているのを
    http://xxx.com/post_type/term というURL表記にするために、削除したAdd RewriteRuleを復活させましたが、URL表記は上記のようになるのですが、404エラーとなってしまいます。(404.php)

    こちらでもtaxonomy.phpを表示させたいのですが、
    ご教授頂けますと幸いです。。

    モデレーター のむらけい (Kei Nomura)

    (@mypacecreator)

    トピック投稿者 nogud

    (@nogud)

    mypacecreatorさん

    ありがとうございます。

    頂いたリンク先の内容を一通り試しましたが、やはり404でした。
    何がおかしいのかさっぱりです。。

    現状のソースはこちらです。

    register_post_type(
    	'blog',
    	array(
    		'label' => 'Blog',
    		'public' => true,
    		'hierarchical' => false,
    		'query_var' => false,
    		'capability_type' => 'post',
    		'menu_position' => 25,
    		'has_archive' => true,
    		'rewrite' => array('slug' => 'blog'),
    		'exclude_from_search' => false,
    		'supports'=> array('title'),
    		'taxonomies' => array('blogcat'),
                'labels' => array (
                	'name' => 'Blog',
                    'singular_name' => 'Blog'
                )
    
    		)
    	);
    	register_taxonomy(
        'blogcat',
        'blog',
        array(
          'hierarchical' => true,
          'query_var' => true,
          'rewrite' => array( true ),
          'label' => 'カテゴリー',
          'singular_label' => 'カテゴリー',
          'show_ui' => true
        )
    );
    
    //Add RewriteRule
    function my_custom_post_type_permalinks_set($termlink, $term, $taxonomy){
    	return str_replace('/'.$taxonomy.'/', '/', $termlink);
    }
    add_filter('term_link', 'my_custom_post_type_permalinks_set',11,3);

    よろしくお願いいたします。

    トピック投稿者 nogud

    (@nogud)

    自己解決しましたのでご報告です。

    パーマリンク設定→共通設定にてカスタム構造にチェックを入れており、下記のように設定しておりました。

    /%category%/%year%%monthnum%%day%%hour%%minute%%second%.html

    このcategory部分をblogcatに変更したところ404エラーがなくなりtaxonomy.phpテンプレートが適用されるようになりました。

    知識が足らず、なぜ正常に反映されるようになったのかは不明ですが、ご報告までに。

    mypacecreatorさん、おつきあいいただきありがとうございました。

10件の返信を表示中 - 1 - 10件目 (全10件中)
  • トピック「カスタムタクソノミーのタームページ(一覧表示)の404エラーについて」には新たに返信することはできません。