Displaying Recent Questions

Solved5.41K viewsCore
0

@RahulAryan — I got your code to do this:

<?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; 
?>

I have a few questions:

  1. Where do I put this code? Would it go in a specific PHP file?
  2. Is there a way to make a new class for the shortcode so this code won’t affect the shortcode I use for the full page?

Thanks.

0

You can put this file directly in php file, where you want to show. Or if you want a easier way, simply install this plugin: https://wordpress.org/plugins/shortcode-exec-php/ and then then you can add above code directly to widget.

Is this code effecting AnsPress shortcode ? or any other plugin shortcode ?

Ok, so I use the shortcode to display all questions on a questions page, but i’d also like to use a shortcode to display the 5 most recent posts on the homepage without using a widget because there is no space for a widget in my theme.

Then in home.php you can directly add my give code, that’s simple.

Hmm — I don’t think that would work — i need it in a specific place on the home page next to two more divs which will contain information from two other plugins. Is there any way to have the php entered in on the html for that section? Or, better yet, to create a new class/property of the shortcode that would allow for this?

Hi Rahul — I just wanted to see if you were able to create a new property for the shortcode to allow for this. I’m currently using a workaround solution, but the next link (and the page number links) just produce an error message. I think this is because this particular instance of the shortcode is on the homepage, but the basepage for the plugin is a different page.

Thanks Rahul! I think we can mark this as fixed. 🙂

Thanks for letting us know.