I am using the following code to display media files on a custom static page. Files display properly but pagination is not working. How can I solve this issue?
Following code shows the media files:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'attachment',
'posts_per_page' => '10',
'paged' => $paged,
/* 'numberposts' => -1, */
'post_status' => null,
'author' => $current_user->ID,
'post_parent' => $post->ID,
/* 'caller_get_posts' => 1, */
);
// The Query
$query = new WP_Query( $args );
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<tr><td><a href="' . wp_get_attachment_url( $attachment->ID ) .
'" rel="shadowbox" title="' . $attachment->post_excerpt . '">';
echo ($attachment->_wp_attached_file);
echo '</a>
</td>';
</tr>';
}
}
Added following to functions.php:
if ( ! function_exists( 'my_pagination' ) ) :
function my_pagination() {
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $wp_query->max_num_pages,
'prev_next' => True,
'prev_text' => __( '« Previous' ),
'next_text' => __( 'Next »' ),
'type' => 'plain',
'add_args' => False,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
) );
}
endif;
Page number or pagination not working, calling the function in my static page like so:
echo my_pagination( $args );