Conditional for last page of posts are paginated
-
I’m working with a Genesis Framework based theme and trying to display some additional information (using ACF) after the content of the post. All works fine with that.
The part I’m having trouble with is for some of the longer posts, I’m paginating them. And I’d like to show this additional content after the content of the post, but only on the last page, if paginated. Right now I’m working just working with the single.php page template.
I did find a question here of similar nature, but I couldn’t seem to get it working. Here’s the code I’m using:
//* Add Resources below references (if any) or below content if (get_field('resources')){ $current_page = $wp_query->get( 'paged' ); if ( $current_page == $wp_query->max_num_pages ) { add_action( 'genesis_entry_content', 'list_resources' ); function list_resources(){ echo '<div class="resources"><h5>Resources</h5>'; echo '<ul class="resource-list">'; if(get_field('resources')): while(has_sub_field('resources')): $attachment_id = get_sub_field('resource_element'); $url = wp_get_attachment_url( $attachment_id ); $path_info = pathinfo( get_attached_file( $attachment_id ) ); echo '<li class="'; echo $path_info['extension']; echo '"><a href="'; echo $url; echo '">'; echo the_sub_field('resource_name'); echo '</a></li>'; endwhile; endif; echo '</ul></div>'; } } }
- The topic ‘Conditional for last page of posts are paginated’ is closed to new replies.