0

过去有几个人出现过这个问题,但他们的问题的解决方案对我不起作用,我已经尝试了很多!

在 Wordpress 中,我创建了 3 种自定义帖子类型。1 用于“视频”、“新闻”和“音乐”,每个都发布到自己的页面。我想添加自定义字段,例如,我可以为音乐帖子添加“艺术家”、“发行年份”、“精选”和“关于专辑”。

我已经安装了高级自定义字段,我可以向其中的每一个添加自定义字段,因此当用户单击“添加新”时,这些字段是可见的。但我遇到的问题是,当我访问页面时,这些字段的输出没有显示在网站上。

我从 single.php 文件中创建了 news.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' );

有谁知道我缺少什么来完成这项工作或我需要做什么。

任何建议都非常感谢。

4

2 回答 2

0

要在循环中显示自定义字段的值,您可以使用以下代码片段:

<?php query_posts( 'post_type=music'); ?>
  <?php while ( have_posts() ) : the_post(); ?>
   <?php get_template_part( 'content',  get_post_format() ); ?>

   <?php $what_name_you_want=get_post_meta($post->ID,'Your Custom Field Name',true); ?>

    <?php echo $what_name_you_want; ?>// This call the value of custom field


                <?php comments_template( '', true ); ?>
            <?php endwhile; // end of the loop. ?>

告诉我它是否有效!

于 2013-04-21T11:06:29.383 回答
0

从 ACF 输出自定义字段数据。

the_field('the-field-name');

get_field('the-field-name') 用于条件 ex if (get_field('my-field'): 等。您还可以使用打印内容

echo get_field('the-field-name');

我会说您对 Vimeo 短代码和自定义字段的问题可能与为通过自定义字段运行而构建的插件有关。可能是它只通过 the_contents() 检查短代码。

于 2013-11-25T17:34:21.593 回答