How to display Questions and Answers on one single page?
Hello, is it possible to view all Questions with the Answers on one page with pagination?
I tried to setup my own template overrides for Anspress, but the following code shows all the quesions but as well every answer under the questions. But I want to view only the answer for the coresponding question.
Thanks in advance!
content-list.php
<?php
/**
* Question list item template
*
*<a class="ap-mention-link" href="https://anspress.io/user/link">@link</a> https://anspress.io
*<a class="ap-mention-link" href="https://anspress.io/user/since">@since</a> 0.1
*<a class="ap-mention-link" href="https://anspress.io/user/license">@license</a> GPL 2+
*<a class="ap-mention-link" href="https://anspress.io/user/package">@package</a> AnsPress
*/
if ( ! ap_user_can_view_post(get_the_ID() ) ) {
return;
}
global $post;
$clearfix_class = array( 'ap-questions-item clearfix' );
$have_permission = ap_user_can_read_answer( $post );
?>
<!-- Frage -->
<div id="question-<?php ap_question_the_ID(); ?>" <?php post_class($clearfix_class ); ?>>
<div class="ap-questions-inner">
<div class="ap-questions-summery no-overflow">
<p class="post-meta">
<?php the_author(); ?>, <?php ap_question_the_time(); ?>
</p>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
</div>
<!-- /Frage -->
<!-- Antwort -->
<?php ap_question_the_answers(); ?>
<!-- /Antwort -->
anwers.php
<?php
/**
* Answers content
*
* Control the output of answers
*
*<a class="ap-mention-link" href="https://anspress.io/user/link">@link</a> https://anspress.io/anspress
*<a class="ap-mention-link" href="https://anspress.io/user/since">@since</a> 2.0.1
*
*<a class="ap-mention-link" href="https://anspress.io/user/package">@package</a> AnsPress
*/
?>
<?php if(ap_have_answers()): ?>
<div id="ap-answers-c">
<?php if(ap_user_can_see_answers()): ?>
<div id="answers">
<?php
$i = 1;
while ( ap_have_answers() ) : ap_the_answer();
include(ap_get_theme_location('answer.php'));
$i++;
endwhile ;
?>
</div>
<?php else: ?>
<div class="ap-login-to-see-ans">
<?php
printf(__('Please %s or %s to view answers and comments', 'anspress-question-answer'), '<a class="ap-open-modal ap-btn" title="Click here to login if you already have an account on this site." href="#ap_login_modal">Login</a>', '<a class="ap-open-modal ap-btn" title="Click here to signup if you do not have an account on this site." href="#ap_signup_modal">Sign Up</a>');
?>
</div>
<?php do_action('ap_after_answer_form'); ?>
<?php endif; ?>
</div>
<?php endif; ?>
answer.php
<?php /** * Answer content * *<a class="ap-mention-link" href="https://anspress.io/user/author">@author</a> Rahul Aryan <[email protected]> *<a class="ap-mention-link" href="https://anspress.io/user/link">@link</a> https://anspress.io/anspress *<a class="ap-mention-link" href="https://anspress.io/user/since">@since</a> 0.1 * *<a class="ap-mention-link" href="https://anspress.io/user/package">@package</a> AnsPress */ global $post; $have_permission = ap_user_can_read_answer( $post ); ?> <div id="answer_<?php the_ID(); ?>" <?php post_class() ?> data-id="<?php the_ID(); ?>"> <div class="ap-q-inner"> <div class="ap-answer-content ap-q-content" itemprop="text"> <p class="post-meta"> <?php the_author(); ?>, <?php ap_answer_the_time(); ?> </p> <h2 class="entry-title">Meine Antwort:</h2> <?php the_content(); ?> </div> </div> </div>
Question List
To display Questions and Answers on a single page, you can design the layout so each question is immediately followed by its corresponding answer, ensuring a smooth reading flow without the need for multiple clicks or page loads. This can be achieved using a simple HTML structure, FAQ plugins, or collapsible/accordion sections that reveal answers when the user clicks on a question, keeping the page organized and easy to navigate. Styling with clear headings, spacing, and readable fonts will make the Q&A section more engaging and user-friendly.
Hello,
In single question page or question list?