Results Text
Ajax Load More offers a simple method to provide feedback to users about the current page, post count and the total number of pages available in a load more query.
By adding the following HTML snippet to any page where Ajax Load More is active, the end user will be presented with text on the screen informing them of their progress through the load more process.
<!-- Renders: Viewing 5 of 20 results. -->
<div class="alm-results-text"></div>
HTMLNote: Results Text can only be used when a single instance of Ajax Load More is present and is not compatible with the Comments add-on.
Adding the HTML
The HTML snippet can be added to your page anywhere you like. If Ajax Load More is able to locate the element, it will render the results text.
<body>
<div id="content">
<div class="alm-results-text"></div>
<?php echo do_shortcode( '[ajax_load_more ...]' ); ?>
<!-- ... the rest of your content -->
</div>
</body>
PHP🔥 Pro Tip: Use the alm_before_button filter hook to inject the text directly into the Ajax Load More listing.
add_filter( 'alm_before_button', function(){
return '<div class="alm-results-text"></div>';
});
PHPDisplay Variables
The following variables can be used to customize the results text for users. These variables can be accessed using the alm_display_results filter hook.
{post_count} | The total number of posts loaded. |
---|---|
{total_posts} | The overall total number of posts. |
{page} | The current page number. |
{pages} | The total number of pages. |
{start} | The number of the first item in view – Paging Add-on only. |
{end} | The number of the last item in view – Paging Add-on only. |
Filter Hooks
The copy displayed to the user in the results text can be updated by using the following filters.
alm_display_results
The alm_display_results filter will updated the feedback text for the user.
// Default: Viewing {post_count} of {total_posts} results.
add_filter('alm_display_results', function(){
return 'Now viewing {page} of {pages} total pages.';
});
PHPalm_no_results_text
The alm_no_results_text filter will change the feedback text when zero posts are returned in the query.
// Default: No results found.
add_filter('alm_no_results_text', function(){
return 'Unable to locate results.';
});
PHP