How to create a pagination for Attachments in Wordpress

Asked

Viewed 63 times

0

Well, if someone knows how to create a pagination for a page that displays the images added in Wordpress, I would appreciate the help, the code I’m using is as follows:

<?php

$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

    $args = array(
                  'posts_per_page' => '30',
                  'post_type' => 'attachment',
                  'paged' => $paged
);

    $myposts = get_posts($args);        
    $the_query = new WP_Query($args);

?>



<?php while ( have_posts() ) : the_post();
global $post;
    foreach( $myposts as $post )  {
        setup_postdata( $post );

echo '<articlep>
  <thumb>
     <a href="';
         the_permalink();
echo '">';
         echo wp_get_attachment_image( get_the_ID());
echo '</a>
   </thumb>
   <ttitle>
     <a href="';
        the_permalink();
echo '">';
        the_title();
echo '</a></ttitle></articlep>';


                }




            endwhile;

     $big = 999999999; 
    paginate_links( array(
                        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 
                        'format' => '&paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $the_query->max_num_pages
   )); 
?>

There at the end I tested a pagination template I found on Wordpress Codex, but it didn’t work. If you want to see how it is now the link is this: http://g-y.one/erus

Thanks in advance.

1 answer

0

Well, for those who need to make a gallery like mine the only way I found to make this pagination was with a plugin calling "Media Library Assistant", then I just had to exchange all that code for:

<?php echo do_shortcode ('
    [mla_gallery post_parent=all numberposts=30 mla_caption="{+title+}" orderby=dateDESC]
');
?>




<div>

<?php echo do_shortcode ('
[mla_gallery post_parent=all numberposts=30 mla_output=paginate_links]
');
?>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.