2016-02-05 83 views
1

我已經創建了一個自定義帖子類型的WordPress與CPT UI名爲雞蛋。WordPress的自定義帖子類型單頁

在名爲eggs.php文件,我把這個代碼:

<?php 
$args = array('post_type' => 'eggs'); 
$query = new WP_Query($args); 
?> 

<?php if ($query->have_posts()) : while($query->have_posts()) : $query->the_post(); ?> 
     <a href="<?php the_permalink(); ?>" Go to Eggs Single Page</a> 
<?php endwhile; endif; wp_reset_postdata(); ?> 

現在我已經創建了一個單eggs.php文件命名,並且當我點擊了永久重定向我在頁面上它說:「對不起,沒有帖子符合你的標準。」 。它不會像我想要的那樣進入頁面single-eggs.php。

編輯:目前我正在使用WebDevStudios的Custom Post Type UI插件。 當我使用OnTheGoSystems的Types插件時,它找到了single-template.php。也許這個插件有問題嗎?

+0

我用另一個插件來使它工作,但我會考慮你的答案作爲將來使用它的一個好的解決方案。非常感謝你! –

回答

0

而不是使用插件來註冊自定義文章你的類型,你可以簡單地使用register_post_type功能,註冊自己的CPT:

function my_cpt_eggs(){ 
    $labels = array(
     'name'       => __('eggs'), 
     'singular_name'     => __('egg'), 
     'menu_name'      => __('eggs'), 
     'all_items'      => __('All eggs'), 
     'add_new'      => __('Add egg'), 
     'add_new_item'     => __('Add New egg'), 
     'edit_item'      => __('Edit egg'), 
     'new_item'      => __('New egg'), 
     'view_item'      => __('View egg'), 
     'search_items'     => __('Search eggs'), 
     'not_found'      => __('Not found'), 
     'not_found_in_trash'   => __('Not found in Trash') 
    ); 
    $args = array(
     'label'       => __('eggs'), 
     'labels'      => $labels, 
     'description'     => __('egg items'), 
     'public'      => true, 
      'exclude_from_search'  => false, 
      'publicly_queryable'  => true, 
      'show_ui'     => true, 
      'show_in_nav_menus'   => true, 
       'show_in_menu'   => true, 
        'show_in_admin_bar' => true, 
        'menu_position'  => 10, 
     'capability_type'    => 'post', 
     'map_meta_cap'     => true, 
     'hierarchical'     => false, 
     'supports'      => array('title', 'editor', 'excerpt', 'thumbnail'), 
     'taxonomies'     => array(), 
     'has_archive'     => true, 
     'query_var'      => true, 
     'can_export'     => true, 
    ); 
} 
add_action('init', 'my_cpt_eggs'); 

把上面的代碼中你functions.php文件。

之後,你可以創建你的single-eggs.php,一切都會好的。

請記住,您可能需要刷新重寫規則。要做到這一點,你應該去

Wordpress Admin > Settings > Permalinks 

,只是打保存設置底部按鈕。

相關問題