Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Add [rc_faq limit="-1"] shortcode
- *
- */
- function rc_faq_shortcode( $atts, $content = null ) {
- extract(shortcode_atts(array(
- "limit" => ''
- ), $atts));
- // Define limit
- if( $limit ) {
- $posts_per_page = $limit;
- } else {
- $posts_per_page = '-1';
- }
- ob_start();
- // Create the Query
- $post_type = 'rc_faq';
- $orderby = 'menu_order';
- $order = 'ASC';
- $query = new WP_Query( array (
- 'post_type' => $post_type,
- 'posts_per_page' => $posts_per_page,
- 'orderby' => $orderby,
- 'order' => $order,
- 'no_found_rows' => 1
- )
- );
- //Get post type count
- $post_count = $query->post_count;
- $i = 1;
- // Displays FAQ info
- if( $post_count > 0) :
- // Loop
- while ($query->have_posts()) : $query->the_post();
- ?>
- <h3 class="rc_faq_title"><a href="#" onclick="rc_faq_toggle('rc_faq_<?php echo get_the_ID(); ?>');"><?php the_title(); ?></a></h3>
- <p id="rc_faq_<?php echo get_the_ID(); ?>" style="display: none;"><?php echo get_the_content(); ?></p>
- <?php
- $i++;
- endwhile;
- endif;
- // Reset query to prevent conflicts
- wp_reset_query();
- ?>
- <script type="text/javascript">
- <!--
- function rc_faq_toggle(id) {
- var e = document.getElementById(id);
- e.style.display = ((e.style.display!='none') ? 'none' : 'block');
- }
- //-->
- </script>
- <?php
- return ob_get_clean();
- }
- add_shortcode("rc_faq", "rc_faq_shortcode");
Advertisement
Add Comment
Please, Sign In to add comment