How can I run it in a page template?

Hi there, I'd like to run the Questions and Answers plugin (one of the templates provided - i.e Question Archives) in a normal WordPress page template. Is this possible? I know you can override the default slug, but I'm interested in pulling in snippets (i.e a list of questions) in a standard page template where necessary. Many thanks.

  • Vinod Dalvi

    Hi @AlDavies,

    I hope you are well today and thank you for your question.

    Yes you can customize Question Archives by copying qa/default-templates/archive-question.php file into your theme folder and start customizing however you want to.

    The customisation instructions that your developer would need for the implementation are located at the bottom of the usage tab here

    You can pull in snippets (i.e a list of questions) in a standard page template where necessary by using following code.

    // The Query
    $args = array( 'post_type' => 'question' );
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '<li>' . get_the_title() . '</li>';
                    // Edit it to display question information whatever you want to
    	}
    } else {
    	echo '<li>No Questions Found</li>';
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    Let me know if you have any doubts doing this.

    Best Regards,

  • AlDavies

    Many thanks Vinod,

    I can now customise the default template, but if I try to use a page template (like below) then I lose the CSS styling and functionality. My intention is to create a few custom page templates to display questions / answers in them where necessary, I could do this by writing new code to call the custom post type, but I'd like to use the existing template so I can keep the vote system etc working. Thanks for your help.:

    <?php
    /*
    Template Name: Show a category of questions
    */
    ?>
  • Vinod Dalvi

    Hi @AlDavies,

    Thanks for reply.

    I can now customise the default template, but if I try to use a page template (like below) then I lose the CSS styling and functionality.

    I saw that you are using custom template and not default qa templates so are you using same class / id which are used in default templates if not then you have to style it yourself.

    Can you just share your site link where you are using Q&A plugin so that i can help you more specifically.

    Best Regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.