這個問題已經出現在過去的幾個人,但他們的問題的解決方案並沒有爲我工作,我已經嘗試了很多!自定義帖子類型的Wordpress自定義字段
在Wordpress中,我創建了3個自定義帖子類型。 1爲'視頻','新聞'和'音樂',每個這些發佈到自己的網頁。我想添加自定義字段,以便我可以爲音樂帖子創建'藝術家''發行年份''特色'和'關於專輯'。
我已經安裝了高級自定義字段,並且我可以向其中的每個添加自定義字段,因此當用戶單擊「添加新的」字段時可見。但我的問題是,當我訪問該頁面時,這些字段的輸出不會顯示在網站上。
我創建news.php,從single.php中文件music.php和videos.php下列要求:
<?php
/**
* Template Name: music Page
*
* Selectable from a dropdown menu on the edit page screen.
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php query_posts('post_type=music'); ?>
<?php the_meta(); ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format()); ?>
<?php comments_template('', true); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
而在functions.php中我有以下幾點:
/*---------music Custom Post Types---------------------------------*/
function my_custom_post_music() {
$labels = array(
'name' => _x('music', 'post type general name'),
'singular_name' => _x('music', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New music'),
'edit_item' => __('Edit music'),
'new_item' => __('New music'),
'all_items' => __('All music'),
'view_item' => __('View music'),
'search_items' => __('Search music'),
'not_found' => __('No music found'),
'not_found_in_trash' => __('No music found in the Trash'),
'parent_item_colon' => '',
'menu_name' => 'Music'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our music and music specific data',
'public' => true,
'menu_position' => 15,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'),
'has_archive' => true,
);
register_post_type('music', $args);
}
add_action('init', 'my_custom_post_music');
function my_taxonomies_music() {
$labels = array(
'name' => _x('music Categories', 'taxonomy general name'),
'singular_name' => _x('music Category', 'taxonomy singular name'),
'search_items' => __('Search music Categories'),
'all_items' => __('All music Categories'),
'parent_item' => __('Parent music Category'),
'parent_item_colon' => __('Parent music Category:'),
'edit_item' => __('Edit music Category'),
'update_item' => __('Update music Category'),
'add_new_item' => __('Add New music Category'),
'new_item_name' => __('New music Category'),
'menu_name' => __('music Categories'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy('music_category', 'music', $args);
}
add_action('init', 'my_taxonomies_music', 0);
/*---------news Custom Post Types---------------------------------*/
function my_custom_post_news() {
$labels = array(
'name' => _x('news', 'post type general name'),
'singular_name' => _x('news', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New news'),
'edit_item' => __('Edit news'),
'new_item' => __('New news'),
'all_items' => __('All news'),
'view_item' => __('View news'),
'search_items' => __('Search news'),
'not_found' => __('No news found'),
'not_found_in_trash' => __('No news found in the Trash'),
'parent_item_colon' => '',
'menu_name' => 'News'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our news and news specific data',
'public' => true,
'menu_position' => 10,
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'),
'has_archive' => true,
);
register_post_type('news', $args);
}
add_action('init', 'my_custom_post_news');
有沒有人知道我錯過了什麼工作或我需要做什麼。
任何建議非常感謝。
<?php the_meta(); ?>在後循環http://codex.wordpress.org/Custom_Fields – 2013-04-21 10:33:14
感謝泰米爾語 - 我已經通讀了解如何解決它,並且我添加了<?php the_meta(); ?>我的帖子循環,但我似乎仍然沒有運氣。有什麼我失蹤或可能我;把它放在錯誤的地方或什麼? – Ciaran 2013-04-21 10:58:27
你修改了哪個文件 – 2013-04-21 11:06:54