Wordpress - 手风琴定制ID(类别)

时间:2012-09-16 11:18:48

标签: wordpress accordion custom-post-type categories

我已经完成了我定义为accordion的自定义帖子类型,我设置了一个简单的手风琴,其中包含短代码。但现在我想知道如何让用户为手风琴制作自己的ID(类别),然后如何用短代码显示该类别(ID)。因为我拥有它,他会显示你制作的每一个新的手风琴帖子,你不能在不同的页面上制作不同的手风琴。

add_action('init', function(){

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

    );
    $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' => false,
        'menu_position' => null,
        'supports' => array('title', 'editor', 'thumbnail', 'page-attributes')
    );
    register_post_type('Accordion', $args);
});

add_shortcode('accordion', function(){

    $posts = get_posts(array(
        'numberposts' => 10,
        'orderby' => 'menu_order',
        'order' => 'ASC',
        'post_type' => 'accordion',
    ));

    $accordion  = '<div id="accordion" class="accordion">'; ///Open the container
    foreach ( $posts as $post ){

        $accordion .= sprintf(('<h2>%1$s</a></h2><div>%2$s</div>'), // Generate the markup for each Question
            $post->post_title,
            wpautop($post->post_content)
        );
    }

    $accordion .= '</div>'; //Close the Container

    return $accordion; //Return the HTML

});

0 个答案:

没有答案