WordPress.org

Ready to get started?Download WordPress

Forums

Media Library Assistant
[resolved] Pagination Revisited (11 posts)

  1. Mike Matenkosky
    Member
    Posted 1 year ago #

    I've been using this to display a specific nuber of thumbnails per page.

    [mla_gallery numberposts="10" offset="" columns="5" attachment_category="landscape" attachment_tag="yosemite" mla_caption="{+title+}" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]
    
    <!--nextpage-->
    
    [mla_gallery numberposts="10" offset="10" columns="5" attachment_category="landscape" attachment_tag="yosemite" mla_caption="{+title+}" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]

    It works fine, but I'd like not to have to add another "page" each time the number of thumbnails gets "full". Is there a way not to have to add <!--nextpage-->? Something to just automatically add a page when the thumbnails gets past a certain number of images?

    http://wordpress.org/extend/plugins/media-library-assistant/

  2. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    What you need is some way to get the number of images, calculate the number of pages, etc.; usually a job for PHP and implemented by the site theme. I can be more helpful if you send the source for the page on which this code occurs.

  3. Mike Matenkosky
    Member
    Posted 1 year ago #

    My 'attachment-image.php' page:

    <?php
    /**
    * My Custon 'attachment-image.php' Page
    * Added PhotoPress Plugin, Prev/Next Links and MLA Gallery Code
    */
    
    get_header(); // Loads the header.php template. ?>
    
    	<div id="content">
    
    		<div class="hfeed">
    
    			<?php if ( have_posts() ) : ?>
    
    				<?php while ( have_posts() ) : the_post(); ?>
    
    					<article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
    
    						<header class="entry-header">
    							<?php echo apply_atomic_shortcode( 'entry_title', the_title( '<h1 class="entry-title">', '</h1>', false ) ); ?>
    						</header><!-- .entry-header -->
    
    						<div class="entry-content">
    
    							<?php if ( has_excerpt() ) {
    								$src = wp_get_attachment_image_src( get_the_ID(), 'full' );
    								echo do_shortcode( sprintf( '[caption align="aligncenter" width="%1$s"]%3$s %2$s[/caption]', esc_attr( $src[1] ), get_the_excerpt(), wp_get_attachment_image( get_the_ID(), 'full', false ) ) );
    							} else {
    								echo wp_get_attachment_image( get_the_ID(), 'full', false, array( 'class' => 'aligncenter' ) );
    							} ?>
    							<div itemprop="description" class="attachment-image-desc">
    								<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'chun' ) ); ?>
    							</div>
    							<?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'chun' ), 'after' => '</p>' ) ); ?>
    
    							<div id="mla-tags">
    								<p><span>Tags: </span>
    									<?php $tax_object = get_taxonomy( 'attachment_tag' );
    										$terms = wp_get_object_terms( get_the_ID(), 'attachment_tag' );
    										if ( !is_wp_error( $terms ) ) {
    											if ( empty( $terms ) )
    												return 'none';
    											$list = array();
    											foreach ( $terms as $term ) {
    												$term_name = esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'category', 'display' ) );
    												$list[ ] = sprintf( '<a href="%1$s/%2$s" title="Gallery for %3$s">%4$s</a>', site_url('media-tags'), $term->slug, $term_name, $term_name );
    											} // foreach $term
    											echo join( ', ', $list );
    										} // if !is_wp_error
    										else {
    											return 'not supported';}
    										?>
    								</p>
    							</div><!-- MLA Attachment Tags -->
    
    							<div id="photo-press">
    								<?php dynamic_sidebar('papt-image-sidebar'); ?>
    							</div><!-- PhotoPress Plugin-->
    
    							<div class="prev-next">
    								<?php
    									if ( isset( $_REQUEST['attachment_category'] ) && isset( $_REQUEST['attachment_tag'] ) ) {
    										$previous_link =  do_shortcode( sprintf( '[mla_gallery mla_output="previous_link" mla_link_text="◄ Previous" numberposts="100" attachment_category="%1$s" attachment_tag="%2$s" id="%3$s" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]', $_REQUEST['attachment_category'], $_REQUEST['attachment_tag'], get_the_ID() ) );
    										$next_link =  do_shortcode( sprintf( '[mla_gallery mla_output="next_link" mla_link_text="Next ►" numberposts="100" attachment_category="%1$s" attachment_tag="%2$s" id="%3$s" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]', $_REQUEST['attachment_category'], $_REQUEST['attachment_tag'], get_the_ID() ) );
    									}
    									else {
    										$previous_link =  previous_image_link( false, '◄ Previous' );
    										$next_link = next_image_link( false, 'Next ►' );
    									}
    								?>
    								<div class="prev"><?php echo $previous_link; ?></div>
    								<div class="next"><?php echo $next_link; ?></div>
    							</div><!-- Custom Prev/Next Links -->
    
    						</div><!-- .entry-content -->
    
    					</article><!-- .hentry -->
    
    					<div class="attachment-meta">
    
    						<?php chun_image_info(); ?>
    
    						<div id="mla-gallery">
    							<?php if ( isset( $_REQUEST['attachment_category'] ) && isset( $_REQUEST['attachment_tag'] ) ) {
    								$gallery = do_shortcode( sprintf( '[mla_gallery exclude="%1$s" columns="4" numberposts="100" mla_style=cleaner mla_markup=cleaner attachment_category="%2$s" attachment_tag="%3$s" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]', get_the_ID(), $_REQUEST['attachment_category'], $_REQUEST['attachment_tag'] ) );
    							} else {
    								$gallery = do_shortcode( sprintf( '[gallery id="%1$s" exclude="%2$s" columns="4" numberposts="100" orderby="rand"]', $post->post_parent, get_the_ID() ) );
    							} ?>
    						</div><!-- Custom MLA Plugin Start-->	
    
    						<?php if ( !empty( $gallery ) ) { ?>
    							<div class="image-gallery">
    								<h3><?php _e( 'Gallery', 'chun' ); ?></h3>
    								<?php echo $gallery; ?>
    							</div>
    						<?php } ?>
    
    					</div><!-- .attachment-meta -->
    
    				<?php endwhile; ?>
    
    			<?php endif; ?>
    
    		</div><!-- .hfeed -->
    
    	</div><!-- #content -->
    
    <?php get_footer(); // Loads the footer.php template. ?>
  4. Mike Matenkosky
    Member
    Posted 1 year ago #

    I just realized that was the wrong file. I'll e-mail it to you instead.

  5. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    I got the file, thanks. I'll have to work thru the details and look at how the theme handles pagination. I won't make much progress until I'm back home, but I will update this topic when I have more information. Thanks for your patience.

  6. Mike Matenkosky
    Member
    Posted 1 year ago #

    No hurry David.

  7. brpubs
    Member
    Posted 1 year ago #

    I've just run into a different type of pagination issue. If I try to filter the library by category -- or, it seems, any filter -- the first page displays correctly. However, if I then click on the arrow to see the next page, it reverts to showing me the full library.

    So, for example, when I filter on one category, it comes up showing that I'm on page 1 of 3. But when I click the next arrow, I end up on page 2 of 8.

    I didn't notice that before this latest update -- but it could be that I just didn't notice it. I did just add several other plug-ins recently, so I suppose it could also be an interaction.

    Thanks!

  8. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    brpubs,

    Thank you for bringing this new MLA defect to my attention. I have opened a separate support topic for it, since it is unrelated to the pagination issues discussed in this topic. You can view the new topic here:

    Pagination Bug in v1.41 Media/Assistant submenu

    I will fix this in the next release and post an update here when that's done.

  9. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    I have released version 1.42, which includes several new features designed to support pagination of [mla_gallery] galleries. The Settings/Media Library Assistant Documentation tab has more information and examples of these new features.

    Your first post in this topic concerns a "paginated single post", where the <!--nextpage--> Quicktag is used to divide a single post or page into two or more pages. I have enhanced the paged=current parameter to better handle this case. You no longer need to code a different offset parameter in each of the shortcodes on the post/page.

    The more general case of building a post/page containing an [mla_gallery] with a large number of items divided among two or more "gallery pages" is handled by the new pagination parameters, mla_output=next_page and mla_output=previous_page. Complete information and examples are in the documentation.

    I will work through the taxonomy-attachment-tag.php file you sent and see what’s required to incorporate the new features in your theme. I'll post an update here with a solution.

  10. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    Here is more information on improving the "paginated single post" part of the topic.

    There are two alternative solutions: 1) you can retain the <!--nextpage--> Quicktags and modify the [mla_gallery] shortcodes to use "paged=current", or 2) you can add the new "mla_output" pagination parameters.

    To retain the <!--nextpage--> Quicktags, the page would look like this:

    [mla_gallery style="launch" numberposts="10" paged=current columns="5" attachment_category="att-category-landscape" attachment_tag="att-tag-yosemite" mla_caption="{+title+}" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]
    
    <!--nextpage-->
    
    [mla_gallery style="launch" numberposts="10" paged=current columns="5" attachment_category="att-category-landscape" attachment_tag="att-tag-yosemite" mla_caption="{+title+}" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]

    The only change I’ve made is to replace the "offset" parameter with "paged=current"; the advantage is that all of the [mla_gallery] shortcodes are now identical. To add another page, just copy and paste. The disadvantage is that to add a page you have to cut and paste…

    Moving on to the alternative using the new pagination parameters, you can re-code the page to handle any number of "gallery pages". You need three [mla_gallery] shortcodes, as shown in the example I added to the Documentation tab:

    [mla_gallery style="launch" numberposts="10" columns="5" attachment_category="att-category-landscape" attachment_tag="att-tag-yosemite" mla_caption="{+title+}" mla_link_href="{+link_url+}&attachment_category={+query:attachment_category+}&attachment_tag={+query:attachment_tag+}"]
    
    <div style="clear: both; float: left">
    [mla_gallery mla_output="previous_page" numberposts="10" attachment_category="att-category-landscape" attachment_tag="att-tag-yosemite"]
    </div>
    <div style="float: right">
    [mla_gallery mla_output="next_page" numberposts="10" attachment_category="att-category-landscape" attachment_tag="att-tag-yosemite"]
    </div>

    I removed the Quicktag and the "paged-current" parameter; MLA will manage the gallery paging. There's a single main gallery shortcode with the "style" and "columns" parameters. There are two new shortcodes for the pagination links. These have no style, columns, mla_caption or mla_link_href parameters (not applicable). They have the new mla_output parameters to generate the appropriate links.

    I surrounded them with some <div> markup to format them. You can add class attributes and such to make them more compatible with your theme.

  11. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    Here is one solution to the "taxonomy-attachment-tag.php" part of your question. This is the file that WordPress looks for whenever it recognizes a query for posts/pages associated with a term in the Att. Tag taxonomy. WordPress parses the link, extracts the taxonomy and term, then uses it to query the database and pass the results to your taxonomy-attachment-tag.php page. Unfortunately, the query WordPress sets up is looking for posts and pages, not attachments, so it returns nothing; the empty page. The first task, then, is to re-query the database and retrieve the appropriate attachments:

    <?php global $wp_query;
    $args = array_merge( $wp_query->query_vars, array( 'post_type' => 'attachment', 'post_status' => 'inherit' ) );
    query_posts( $args );
    ?>

    That cleans things up so we can use the have_posts() function in the main loop. Typically, the main loop would go through each post/attachment and format it for display. What we want instead is an [mla_gallery] that shows the attachments as, well, a gallery.

    <div class="mla-tags-gallery">
    <?php echo do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_caption="{+title+}" columns="5" numberposts="10"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) ); ?>
    </div>

    Finally, there is pagination. The WordPress Codex Pagination article (worth reading) says "There are many pagination plugins to choose from in the plugin repository. Two of the more popular ones that allow you to have numbered pagination are wp-pagenavi and wp-paginate." Both of these plugins (read their Installation instructions) require you to modify the theme files, replacing the theme pagination code with new code that calls their plugin.

    In the file you sent the theme handles pagination by get_template_part( 'loop-nav' );, so we must replace the “loop-nav” code with a couple of “do_shortcode()” calls to get the [mla_gallery] pagination links. The tricky part is surrounding the links with appropriate class and style attributes so they look good in the theme.

    <div class="pagination loop-pagination">
    <?php echo do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_output="previous_page" numberposts="10" mla_link_class="prev page-numbers" mla_link_text="<span class=\'meta-nav\'>◄</span> Previous"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) ); ?>
    <?php echo do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_output="next_page" numberposts="10" mla_link_class="next page-numbers" mla_link_text="Next <span class=\'meta-nav\'>►</span>"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) ); ?>
    </div>

    Putting all the above elements together and adding proper indentation, here is the complete "taxonomy-attachment-tag.php" file:

    <?php
    /**
    * Custom 'taxonomy-attachment_tag.php' for the 'Media Library Assistant-Tags' Plugin
    */
    ?>
    
    <?php get_header(); // Loads the header.php template. ?>
    
    	<?php global $wp_query;
    		$args = array_merge( $wp_query->query_vars, array( 'post_type' => 'attachment', 'post_status' => 'inherit' ) );
    		query_posts( $args );
    	?>
    
    	<div id="content">
    
    		<div class="hfeed">
    
    			<?php get_template_part( 'loop-meta' ); // Loads the loop-meta.php template. ?>
    
    			<?php if ( have_posts() ) : ?>
    
    			<div class="mla-tags-gallery">
    				<?php echo do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_caption="{+title+}" columns="5" numberposts="10"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) ); ?>
    			</div>
    
    			<?php else : ?>
    
    				<?php get_template_part( 'loop-error' ); // Loads the loop-error.php template. ?>
    
    			<?php endif; ?>
    
    		</div><!-- .hfeed -->
    
    		<?php // get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>
    
    		<div class="pagination loop-pagination">
    			<?php echo do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_output="previous_page" numberposts="10" mla_link_class="prev page-numbers" mla_link_text="<span class=\'meta-nav\'>◄</span> Previous"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) ); ?>
    			<?php echo do_shortcode( sprintf( '[mla_gallery %1$s="%2$s"  mla_output="next_page" numberposts="10" mla_link_class="next page-numbers" mla_link_text="Next <span class=\'meta-nav\'>►</span>"]', $wp_query->query_vars['taxonomy'], $wp_query->query_vars['term'] ) ); ?>
    		</div>
    
    	</div><!-- #content -->
    
    <?php get_footer(); // Loads the footer.php template. ?>

    Note that the left and right arrowheads in the "meta-nav" spans are actually coded ampersand-poundsign-9668-semicolon and 9658, respectively.

    I hope that gives you enough information to set up pagination for the [mla_gallery] shortcodes on your site. Thanks for a great question that led directly to the new pagination features in version 1.42.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags