most recent questions on (home)page

4.74K viewsWordPress
0

Hi There,

I want to display the most recent 5 or 10 questions on my homepage.
Are there customization I can make to the standard shortcode to limit the number of questions displayed?
I also found this code:

<?php
ap_get_questions(array('showposts' => 5));
?>

<?php if ( ap_have_questions() ) : ?>
<div class="ap-questions">
<?php
/* Start the Loop */
while ( ap_questions() ) : ap_the_question();
ap_get_template_part('content-list');
endwhile;
?>
</div>
<?php ap_questions_the_pagination(); ?>
<?php
else :
ap_get_template_part('content-none');
endif;
?>

But it gives a:
Sorry! No question found.

While there are hundreds of questions..

0

Hello,
Sorry for delayed answer. Check this widget code for working example.
https://github.com/anspress/anspress/blob/master/widgets/questions.php
cheers.

0

Still not working. My current code is:
<?php
global $questions;
$questions = ap_get_questions(array('showposts' => 5));
?>

<?php if ( ap_have_questions() ) : ?>
<div class="ap-questions">
<?php
/* Start the Loop */
while ( ap_questions() ) : ap_the_question();
ap_get_template_part('content-list');
endwhile;
?>
</div>
<?php ap_questions_the_pagination(); ?>
<?php
else :
ap_get_template_part('content-none');
endif;
?>

The error I get is:
Fatal error: Uncaught Error: Call to undefined function ap_questions()

Please advice 🙂

commented on answer

Rahul, any words of wisdom? 🙂