获取404.php而不是Single-<post-type>.php

时间:2011-09-07 作者:Adam

试图找到一个帖子出现在http://beernews.org/supporter/rare-beer-club/ 但我得到的是404。页面外观的示例如下:http://beernews.org/brewery/5-rabbit-brewery/. 当我进行搜索时,它会在结果中显示为摘录。只是无法获得模板的单个支持者。php由于某种原因触发。我已经设置了与其他所有帖子类型和分类法完全相同的帖子类型(和相应的分类法)。

我已刷新缓存和CDN。

我没有用于此的实时服务器测试环境,但相同的代码可以在localhost上运行。因为它的流量很大,所以我不愿意打开前端显示的调试功能。

在函数中注册post类型代码。php

  $labels = array(
    \'name\' => _x(\'Supporters\', \'post type general name\'),
    \'singular_name\' => _x(\'Supporter\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'supporter\'),
    \'add_new_item\' => __(\'Add New Supporter\'),
    \'edit_item\' => __(\'Edit Supporter\'),
    \'new_item\' => __(\'New Supporter\'),
    \'all_items\' => __(\'All Supporters\'),
    \'view_item\' => __(\'View Supporter\'),
    \'search_items\' => __(\'Search Supporters\'),
    \'not_found\' =>  __(\'No supporters found\'),
    \'not_found_in_trash\' => __(\'No supporters found in Trash\'), 
    \'parent_item_colon\' => \'\',
    \'menu_name\' => \'Supporters\'

  );
  $args = array(
    \'labels\' => $labels,
    \'public\' => true,
    \'publicly_queryable\' => true,
    \'show_ui\' => true, 
    \'show_in_menu\' => true, 
    \'query_var\' => true,
    \'rewrite\' => true,
    \'capability_type\' => \'post\',
    \'has_archive\' => true, 
    \'hierarchical\' => true,
    \'menu_position\' => null,
    \'taxonomies\' => array (\'beer\',\'category\'),
    \'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'excerpt\',\'trackbacks\',\'custom-fields\',\'page-attributes\',\'revisions\',\'comments\',\'post-formats\')
  ); 
  register_post_type(\'supporter\',$args);
在函数中注册分类代码。php

   // Add new taxonomy, make it hierarchical (like categories)
  $labels = array(
    \'name\' => _x( \'Supporters\', \'taxonomy general name\' ),
    \'singular_name\' => _x( \'Supporter\', \'taxonomy singular name\' ),
    \'search_items\' =>  __( \'Search Supporters\' ),
    \'all_items\' => __( \'All Supporters\' ),
    \'parent_item\' => __( \'Parent Supporter\' ),
    \'parent_item_colon\' => __( \'Parent Supporter:\' ),
    \'edit_item\' => __( \'Edit Supporter\' ), 
    \'update_item\' => __( \'Update Supporter\' ),
    \'add_new_item\' => __( \'Add New Supporter\' ),
    \'new_item_name\' => __( \'New Supporter Name\' )
  );

  register_taxonomy(\'supporter\',array(\'beer\',\'post\'),
    array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'supporters-bp\' )
  ));

2 个回复
SO网友:Adam

别客气。出于某种原因,我不得不转到我的永久链接页面,单击“保存更改”以显示该页面。这令人困惑。

SO网友:António Pinto

保存后需要刷新永久链接。

您可以将此函数添加到函数中。php文件:

// ==============================================
// Flush Permalinks on Save Post
// ==============================================

//Create a Function to Flush Permalinks
function nr_flush_permalinks() {
    /* Call WordPress rewrite function to flush rules.
        http://codex.wordpress.org/Rewrite_API/flush_rules */
    $wp_rewrite->flush_rules();
    // Do anything you wish to do more....
}
//Add Function "n_flush_permalinks()" to the "save_post" action hook:
add_action( \'save_post\', \'nr_flush_permalinks()\' );

结束

相关推荐