• Hi all,

    i hope someone could help me with this cause I cant figure out. I’ve setup up a simple accordion but what I want to do is to enable users to make ID for every accordion so different accordion could be used on different posts/pages, and then I would like to setup that id shortcode I have, ex. [accordion id=”1″]..something like that.

    I would be very grateful if someone would help me with that.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jrstudio

    (@jrstudio)

    oh, here is the code I managed to write on my own

    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
    
    });
    Thread Starter jrstudio

    (@jrstudio)

    anyone?

    I could put my own taxonomy but thats not what I rly want.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Accordion help pls?’ is closed to new replies.