Support » Plugin: Media Tags » How can I add pagination to my Media tags code?

  • Resolved surfsup74


    I have the following code in my taxonomy-media-tags.php template file. How do I add pagination to this please so that my page will only display a specified number of photos per page? I’ve see the numberpost parameter that i can use within the ‘get_attachments_by_media_tags’ args but that doesn’t help with pagination. Thanks

    <?php get_header(); ?>
    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
    <?php $media_items = get_attachments_by_media_tags('size=thumb&media_tags='.$term->slug); ?>
    <?php echo '<h1>You are viewing all photos tagged <i>'. $term->name . '</i></h1>'; ?>
    if ($media_items) {
    echo '<ul>';
    foreach ($media_items as $mymedia) {
    $fullSize = wp_get_attachment_url($mymedia->ID);
    $taggedThumbnail = wp_get_attachment_thumb_url($mymedia->ID, 'thumb');
    $associatedPost = get_permalink($mymedia->post_parent);
    $parent_title = get_the_title($mymedia->post_parent);
    $image_title = $mymedia->post_title;
    echo '<li><a href="' . $fullSize . '" rel="shadowbox[set1]" title="Click to view this “'. $term->name . '” photograph in fullscreen. Filename: '. $image_title .'.jpg" ><img src="'.$taggedThumbnail.'" alt="Photograph filename:'. $image_title .'.jpg" /></a>
    <span>This photo can also be seen here: <a href="' . $associatedPost . ' " title="View “'. $parent_title .'”">' . $parent_title . '</a></span>
    </li>'; }
    echo '</ul>'; }  ?>
    <?php // Reset Post Data
    wp_reset_postdata(); ?>
    <?php get_footer(); ?>

Viewing 1 replies (of 1 total)
  • Plugin Author Paul Menard


    On the get_attachments_by_media_tags() function call there are two parameters supported ‘offset’ and ‘numberposts’. Basically any parameter you can pass into get_posts you can pass into that function.

    This means prior to calling the get_attachments_by_media_tags function you need to figure out what page the user is on. Media-Tags does not do that for you. Generally the ‘offset’ value is the number of items per page (numberposts) X page number.

    Hope this helps.

Viewing 1 replies (of 1 total)
  • The topic ‘How can I add pagination to my Media tags code?’ is closed to new replies.