WordPress.org

Ready to get started?Download WordPress

Forums

Media Tags
[resolved] How can I add pagination to my Media tags code? (2 posts)

  1. surfsup74
    Member
    Posted 1 year ago #

    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>'; ?>
    <?php
    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(); ?>

    http://wordpress.org/extend/plugins/media-tags/

  2. Paul Menard
    Member
    Plugin Author

    Posted 1 year ago #

    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 http://codex.wordpress.org/Template_Tags/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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic