Last active
August 29, 2015 14:16
-
-
Save safranck/ebac611d7d2960b5e1e5 to your computer and use it in GitHub Desktop.
Display items from FAQ CPT Using Alternating Background Colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Display the FAQs section | |
*/ | |
function wds_faqs() { | |
echo wds_get_faqs(); | |
} | |
/** | |
* Grab the FAQs content | |
*/ | |
function wds_get_faqs() { | |
// Query for our posts | |
$post_args = array( | |
'post_type' => 'faq', | |
'orderby' => 'menu_order', | |
'order' => 'ASC' | |
); | |
$faqs = new WP_Query( $post_args ); | |
// The Loop | |
if ( $faqs->have_posts() ) { | |
$output = '<div class="faqs-wrap">'; | |
$c = true; | |
while ( $faqs->have_posts() ) { | |
$faqs->the_post(); | |
$output .= '<article class="faq' . (($c = !$c)?' odd':'') . '">'; | |
$output .= '<h3>' . get_the_title() . '</h3>';; | |
$output .= '<div class="hidden">' . wpautop( get_the_content() ) . '</div>'; | |
$output .= '</article>'; | |
} | |
$output .= '</div>'; | |
} | |
/* Restore original Post Data */ | |
wp_reset_postdata(); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment