• Resolved LouisIsMyDog

    (@louisismydog)


    Hi,

    I am using your plugin MLA. I need help creating pagination and part of the problem is that, I just discovered when you use your Media Assistant => Bulk Editor for adding tags to the images. What you are really doing is adding attachemnt_tags different from the standard wordpress tags. Which is why I am having trouble showing all of my media posts with generic wordpress pagination functions in my single-attachment.php page.

    So my pages have your [MLA gallery shortcode]. The shortcode shows images with a link to their attachment page. Now I want to paginate the attachment page with a “Previous,Next” nav bar to scroll through the attachment pages withing the same tag, taxonomy, attachment_tag, term_id whatever you want to call it. How would I go about doing this? The link to my attachment page of any product is http://capa.furniture/?attachment_id=1405 On a side note, plz disregard the wordpress debug I have been running to find out what is going on with my taxonomies.
    This is the page where I am using your [MLA plugin]

    Thanks in advance for your help!

    -Emre

    https://wordpress.org/plugins/media-library-assistant/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author David Lingren

    (@dglingren)

    Paginating and navigating the WordPress “attachment pages” can be done, but it is painful, theme dependent and requires PHP coding. Here are three earlier support topics that discuss the techniques:

    Pagination Revisited

    Category template please help

    Category template for Media Library Assistant with pagination

    Topics like these inspired MLA improvements to handle pagination without requiring template changes or PHP coding. Here is a section I am adding to the Settings/Media Library Assistant Documentation tab in my next release:

    A Paginated Gallery

    If your gallery display includes a large number of items it may be useful to divide the display into “pages” with a fixed upper limit of items per page. The Documentation’s “Support for Alternative Gallery Output, e.g., Pagination” section explains several ways to do that; here is one example:

    [mla_gallery attachment_category=big-dog posts_per_page=12]
    
    [mla_gallery attachment_category=big-dog posts_per_page=12 mla_output="paginate_links,prev_next"]

    Put both of these shortcodes on a post or page to display a paginated gallery. The first [mla_gallery] displays the images assigned to attachment_category=big-dog and displays a maximum of 12 images at once. The second [mla_gallery] has exactly the same data selection parameter and posts per page parameter; that’s essential to match up with the first shortcode. It adds one more parameter, mla_output. This parameter changes the display from a set of images to a set of pagination controls.

    MLA will add and manage a “current page” parameter of its own so the two shortcodes stay in synch as you navigate from page to page. That’s all there is to it.

    ———-

    You can simulate the “attachment page” by adding size=full and posts_per_page=1 to the above shortcodes. I encourage you to experiment with the above and see if you can complete your application without resorting to modifying the PHP code in the template files.

    I will leave this topic unresolved until I hear back from you. Thanks for your interest in the plugin.

    Thread Starter LouisIsMyDog

    (@louisismydog)

    Sorry for the duplicate post, there was some sort of error while posting.

    Anyway, I know I need to edit the the themes template file. That is no problem. I already created a new single-attachment.php in a child theme. The problem is that when you go into the mysql database I cannot find the column/row where the tag attribute has been added from the Media Library Bulk Editor. I do not know how the information is stored therefore I cannot write the right php code. I do not know how your code saves the images on the database. I say this because under taxonomy => post_tag => “my tags” do not show has I have any posts attached to the tags I created though the MLA Bulk Editor. Which means the attributes are stored elsewhere.

    This code spits out “No”.

    <?php
    if (taxonomy_exists('my_taxonomy')) {
    print "YES";
    }
    else {
    print 'NO';
    }
    
    ?>

    Let me know if you understand what I am looking for.

    Plugin Author David Lingren

    (@dglingren)

    Thank you for your update with the additional details.

    MLA uses WordPress features and conventions wherever possible. Uploading and image storage is all done with WordPress code – there are no special database tables or file structures created by MLA.

    The “Att. Categories” (slug attachment_category) and “Att. Tags” (slug attachment_tag) added by MLA are stored in WordPress custom taxonomies, and all of the WordPress functions for managing taxonomies and terms work without change. You can also add support for the built-in WordPress Categories (slug category) and Tags (slug post_tag) for Media Library items/attachments, but you must enable that by going to the Settings/Media Library Assistant General tab, scrolling down to the “taxonomy Support” section and making some changes. If you haven’t done that you can find the terms you assigned in the attachment_category and attachment_tag taxonomies.

    Since it sounds like you are prepared to do some PHP coding you might find it helpful to look through the templates and functions in the /media-library-assistant/examples/twentytwelve-mla/ child theme directory. There are several examples of accessing and using the various taxonomies in the files there.

    I hope that gives you some answers. Please keep posting if you have problems or further questions regarding taxonomy support in MLA.

    Thread Starter LouisIsMyDog

    (@louisismydog)

    I have been working on this for a while now and I still cannot seem to figure it even while trying to dissect the shortcodes in your “twentytwelve-mla” directory.

    I am still trying to add a pagination “Next and Previous” for all items in the gallery within the mla gallery tag. The only difference is that this is for the attachment page of the posts.

    I have spent countless hours on this small code.

    Thanks in advance.

    Thread Starter LouisIsMyDog

    (@louisismydog)

    I need something that gets the current attachment-page’s post_id (something like wp_attachment_is_image($post->id) and then from there my code should be able to see what tag is associated with that post_id (something like $posttags = get_the_tags();) after I need to be able to get all other href links to all other post_ids attached to the same tag to create the pagination.

    Does this make sense. I know you have already built this into your MLA Gallery plugin. I just do not know how to incorporate this to my webpage.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your updates and for all the work you’ve put in to understand the examples and apply them to your application. I know from my own experience how frustrating even “small code” can be.

    If it is possible I would like to have a look at your child theme or at least the complete single-attachment.php file. . If you send me your contact information I can give you an e-mail address you can use to send a copy of the file(s). You can use the Contact Us page at the FTJ web site:

    Fair Trade Judaica/Contact Us

    Once I see all of the code I will try to work with you to make it work. Thanks for your understanding and your patience.

    Thread Starter LouisIsMyDog

    (@louisismydog)

    You can find the contents to my child theme here Drop Box. The attachment page template file is single-attachment.php. The theme that I am using is Virtue Premium and the contents to that are here Virtue Premium.

    Thanks again for all your help.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for posting your code to Dropbox. I was able to download both of the items and I will have a look at them shortly.

    Thread Starter LouisIsMyDog

    (@louisismydog)

    Thanks again for your help 🙂

    Plugin Author David Lingren

    (@dglingren)

    I have installed the Virtue Premium theme and your child theme on one of my test sites and I have had a look at your single-attachment.php template.

    Your code uses WordPress functions such as get_the_tags(), which is hard-wired to the built-in WordPress Tags (slug post_tag). Earlier you wrote about “tags I created though the MLA Bulk Editor“. I am guessing that those tags are stored in the “Att. Tags” (slug attachment_tag) added by MLA, which is why they are not returned by this function. When you go to the Media/Assistant Bulk Edit area, does the label above the text area say “Att. Tags” or “Tags”?

    You might try something like this:

    $posttags = get_the_terms( $post->id, 'attachment_tag' );

    The pagination code at the bottom of the template uses calls like get_children() to find the next and previous images in the “gallery”. This is an old WordPress convention that assumes all the images in the gallery are “attached” to the parent post. If you are using an [mla_gallery] shortcode to display a gallery filtered by attachment_tag values, none of this will work.

    The best way to work through these issues with you is an e-mail dialog. Please use the Contact Us page at the FTJ web site (Fair Trade Judaica/Contact Us) to give me your contact information so we can continue our communications more easily. Thanks for your understanding.

    Thread Starter LouisIsMyDog

    (@louisismydog)

    In the Media/Assistant Bulk Edit area, the label above says Tags.

    You can communicate with me through my email: emre.bilgin@icloud.com.

    Plugin Author David Lingren

    (@dglingren)

    Thank you for working with me offline to update your product category [mla_gallery] shortcodes and your single-attachment.php template to add “Previous” and “Next” pagination links for the single attachment pages within the product category. Some of the changes are theme-specific, but I am summarizing them here so other users can adapt them to their applications.

    The first step is passing the selected tag from the gallery to the attachment page. You must modify the shortcodes in your product category pages to do this. For example:

    [mla_gallery tag=ottomans order=ASC mla_caption="{+template:({+title+}|{+caption+}|{+description+})+}" mla_link_href="{+site_url+}?attachment_id={+attachment_ID+}&term_slug={+query:tag+}" size=full posts_per_page=15]

    Note the new mla_link_href parameter that adds “term_slug” to the query string.

    The next step is adding previous/next link logic to the single-attachment.php template:

    <?php if ( isset( $_REQUEST['term_slug'] ) ): ?>
                    <nav id="image-navigation" class="navigation" role="navigation"> <span class="previous-image">
                    <?php echo do_shortcode('[mla_gallery tag=' . $_REQUEST['term_slug'] . ' order=ASC mla_output="previous_link" mla_link_text="← Previous" mla_link_href={+link_url+}&term_slug={+query:tag+}]')?>
                    </span> <span class="next-image">
                    <?php echo do_shortcode('[mla_gallery tag=' . $_REQUEST['term_slug'] . ' order=ASC mla_output="next_link" mla_link_text="Next →" mla_link_href={+link_url+}&term_slug={+query:tag+}]')?>
                    </span>               </nav>
    <!-- #image-navigation -->
    <?php else: ?>
                    <nav id="image-navigation" class="navigation" role="navigation"> <span class="previous-image">
                    <?php previous_image_link( false, __( '← Previous', 'twentytwelve' ) ); ?>
                    </span> <span class="next-image">
                    <?php next_image_link( false, __( 'Next →', 'twentytwelve' ) ); ?>
                    </span> </nav>
    <!-- #image-navigation -->
    <?php endif; ?>

    This code tests for the presence of the “term_slug” and uses a do_shortcode to generate the pagination controls if it is found. If “term_slug” is not found, normal WordPress pagination is performed.

    That’s a summary of the solution. I am marking this topic resolved, but please update it or let me know if you have any other problems or questions about adding navigation links using [mla_gallery].

    Thank you as well for your positive MLA review and for your donation in support of the plugin and our work. Both are great motivators to keep working on the plugin and supporting its users.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Need help creating pagination for attachment page!’ is closed to new replies.