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

    (@dglingren)

    Thanks for your question; you wrote “next image in the category“, which has two parts:

    1. next image
    2. image in the category

    Moving to the next or previous image (the first part of your question) is supported by the next_link and previous_link values of the [mla_gallery] mla_output parameter. You can find more information about the parameter and its values in the “” section of the Settings/Media Library Assistant Documentation tab. This will give you the links you need and thumbnail support is included. The Documentation tab includes examples that show how to incorporate taxonomy terms such as category or tag to answer the second part of your question. In your case, the “single-image page” in the example is your attachments.php file, so you don’t want:

    mla_link_href="{+site_url+}?page_id=893&current_id={+attachment_ID+}&attachment_tag={+query:attachment_tag+}"

    You can use something like:

    mla_link_href="{+pagelink+}&attachment_tag={+query:attachment_tag+}"

    This earlier support topic includes more information along similar lines:

    Next Link progression through categories + slugs

    Let me know if the material I referred to is sufficient and if you have problems or further questions about the suggested solution. I will leave this topic unresolved until I hear back from you.

    Thread Starter TallSam

    (@tallsam)

    Hi David,

    I’ve been looking through all the material you provided and it is very much over my head. The one thing I have been able to figure out is that I can get the next image attachment page simply with <?php next_image_link( false ); ?>.

    If I could just limit it to a MLA category, I would be set. Any suggestions on how I can do this? I did look through your earlier support topic on this and tried some of the code but without much luck. I’m hoping for something simple here… I’m quite new to all this and greatly appreciate your help.

    Thanks,
    Sam

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and for taking the time to go through the materials I pointed you to in my previous post. Linking and pagination has been a recurring topic in the MLA support forum and I know it can be complicated unless you have a fair amount of WordPress coding experience.

    The WordPress next_image_link() function won’t help you because it “creates a link to the next image attached to the current post.” All of the WordPress functions assume that Media Library items are “attached” to a parent post/page; hence the traditional “attachments” terminology. Starting in WP 3.5 this notion has been deprecated, and plugins like MLA give you taxonomy support and shortcodes like [mla_gallery] to compose gallery displays in a variety of ways.

    This is why MLA includes the mla_output parameter and its own support for linking and pagination. With mla_output and [mla_gallery] you can create an “attachment page” of your own, as a standard WordPress Page, without modifying your theme’s attachment.php file. Even if your application requires a modified attachment.php file you can experiment with the simpler approach to get more understanding of what’s required.

    You don’t say how the “category” for your [mla_gallery] is selected, and it’s not clear whether you use the MLA-provided “Att. Categories” taxonomy or the WordPress “Categories” taxonomy. Here is an example of a WordPress “Cloud and Gallery” page that uses the [mla_tag_cloud] and [mla_gallery] to select a term from the “Att. Categories” taxonomy and display the resulting images:

    <h3>The Cloud</h3>
    Click on a term to populate the gallery below.
    
    [mla_tag_cloud taxonomy=attachment_category number=0 mla_link_href="{+page_url+}?term_slug={+slug+}"]
    
    <h3>The Gallery</h3>
    
    [mla_gallery attachment_category="{+template:({+request:term_slug+}|a-bad-term)+}" mla_nolink_text="Click a term in the above cloud." mla_link_href="/single-image-from-cloud-and-gallery/?current_id={+attachment_ID+}&attachment_category={+request:term_slug+}"]

    The [mla_tag_cloud] displays Att. Categories terms in the familiar cloud format. The number=0 parameter ensures that all of the terms are displayed. The mla_link_href parameter links each term back to the current page ({+page_url}) and passes a variable back with the term selection (?term_slug={+slug+}). If you put the [mla_tag_cloud] shortcode on another page or in a widget you will have to hard-code the URL portion of the link.

    The [mla_gallery] displays the images assigned to the selected attachment_category term. The mla_nolink_text parameter gives the text to display when the gallery is empty, e.g., before you click on a term. In this shortcode:

    • The template: prefix says that this is a Content Template
    • The parentheses “()” around the two elements are used to group them into a list of alternatives
    • The vertical bar “|” between the two elements means “stop when you get a non-empty alternative”
    • {+request:term_slug+} will be empty unless there is a term_slug in the URL
    • a-bad-term is a literal value (and thus never empty) which does not match any term in the attachment_category taxonomy, so the gallery will be empty if this alternative is used
    • The mla_nolink_text parameter gives some text displayed when the gallery is empty, i.e., before a term is selected
    • The parameter links each item to the new “Single Image” page defined below.

    To use this example, add a new WordPress page titled “Cloud and Gallery for Single Image” at the root level of your site and paste in the above content (use the “Text” tab, not the “Visual” tab). If you have your own way of selecting a category you can omit the cloud. As you know, the default link from each gallery item will go to the “attachment page” for that item. Using the mla_link_href parameter in the [mla_gallery] shortcode you can change this to go to another standard WordPress Page (or any other destination). Let’s break down the elements in this parameter:

    • /single-image-from-cloud-and-gallery/ is the URL of the standard WordPress page created for the “Single Image” display.
    • current_id={+attachment_ID+} passes the ID of the gallery image clicked on to the Single Image page
    • attachment_category={+request:term_slug+} passes the Att. Category term from the gallery to the Single Image

    To create the “Single Image” page, add a new WordPress page titled “Single Image from Cloud and Gallery” at the root level of your site. Then add this content to that page:

    <table><tr>
    <td style="text-align: left">
    [mla_gallery mla_output="previous_link,wrap" mla_link_text='&larr; Previous Image' attachment_category="{+request:attachment_category+}" id="{+request:current_id+}" mla_rollover_text="{+title+}" mla_link_href="{+page_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"]
    </td>
    <td style="text-align: center">
    <a href="/cloud-and-gallery-for-single-image/" title="Back to the Cloud and Gallery page">Back to Gallery</a>
    </td>
    <td style="text-align: right">
    [mla_gallery mla_output="next_link,wrap" mla_link_text='Next Image &rarr;' attachment_category="{+request:attachment_category+}" id="{+request:current_id+}" mla_rollover_text="{+title+}" mla_link_href="{+page_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"]
    </td>
    </tr></table>
    
    [mla_gallery columns=1 ids="{+request:current_id+}" size=full]

    The <table> ... </table> markup is there just to format the previous, gallery and next links clearly on a single line. Below the links is a single-item [mla_gallery] to display the full-size image of the selected item.

    Let’s break down the previous and next [mla_gallery] shortcodes:

    • mla_output="previous_link,wrap" (and next_link,wrap) instructs [mla_gallery] to display the previous and next links. The ,wrap portion makes the links wrap around to the other end of the gallery from the first and last items.
    • mla_link_text='&larr; Previous Image' (and Next Image &rarr;) gives the labels displayed for the links.
    • attachment_category="{+request:attachment_category+}" is the data selection parameter that restricts the links to stay within the bounds of the selected Att. Category.
    • id="{+request:current_id+}" gives the ID value of the “current item”. It is first set in the gallery page and updated each time the previous or next link is clicked.
    • mla_rollover_text="{+title+}" adds the Title of the previous/next item to the previous and next links; it appears as a “tooltip” when you hover over the links.
    • mla_link_href gives the destination and query parameters for the previous/next link. Its elements are:
    • {+page_url+} (the URL element) is a convenient way to come back to the current page.
    • current_id={+attachment_ID+} updates the ID to the previous/next item in the Att. Category.
    • attachment_category={+query:attachment_category+} limits the items to the selected Att. Category.

    There you have it – a complete solution that does not require any PHP coding or theme modification. If you do want to incorporate this in your attachment.php template, the two [mla_gallery] shortcodes for the previous and next links become do_shortcode() statements. You still have to use the attachment_category query parameters to stay within the Att. Category, but you can use something like $id = get_the_ID(); in place of the current_id argument. I can help with that if you’d like me to.

    Give the examples a try and let me know how they work for you. If you have problems or further questions I am happy to help. Thanks for your persistence and your interest in the plugin.

    Thread Starter TallSam

    (@tallsam)

    I tried this in my attachments.php file, but got the white screen of death ??

    <?php echo do_shortcode(' [mla_gallery mla_output="next_link,wrap" mla_link_text='Next Image &rarr;' attachment_category="{+request:attachment_category+}" id="{+request:current_id+}" mla_rollover_text="{+title+}" mla_link_href="{+page_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"]' ); ?>

    I swapped out current_id with $id = get_the_ID(); but still the same issue, though I suspect you didn’t mean an exact swap of those terms…

    Any suggestions?

    This plugin is becoming fairly essential to my site. So I’m wondering what your long term plans are for it. Will you continue supporting it, make it for profit, bring in other developers, or make it open source etc.?

    Thank you kindly for your time,
    Sam

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and for taking the time to include the source code for your do_shortcode() statement.

    I have never had the “” as a result of a valid [mla_gallery] shortcode. The most common reason for this result is a lack of memory, but that seems unlikely in this case. You can try the fix in this earlier topic:

    MLA stopped working after installing Themeco X theme

    It is more likely that some invalid PHP code is causing the problem. For example, your short code has single quotes in one parameter: mla_link_text='Next Image →' – try changing these to double quotes to avoid the conflict with the single quotes around the entire shortcode.

    Beyond that, I would suggest a step-by-step approach to getting this statement working. Start by hard-coding the values for the attachment_category and id values:

    <?php echo do_shortcode(' [mla_gallery mla_output="next_link,wrap" mla_link_text='"Next Image →" attachment_category="my-category" id="999" mla_rollover_text="{+title+}" mla_link_href="{+page_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"]' ); ?>

    Where “my-category” and “999” are replaced by values you know to be correct. In particular, do you know that attachment_category and current_id are being passed in to the page? You can add something like this to verify that:

    <?php echo '$_REQUEST = ' . var_export( $_REQUEST, true ) . "<br>"; ?>

    If you don’t see attachment_category and current_id in the output you have not set them up in the [mla_ggallery] shortcode that links to this page. You can also verify that the ID value is correct by something like

    <?php echo 'ID = ' .  get_the_ID() . "<br>"; ?>

    To get the ID value from WordPress instead of the current_id parameter you can do something like this:

    <?php
    $id = get_the_ID();
    echo do_shortcode(' [mla_gallery mla_output="next_link,wrap" mla_link_text='"Next Image →" attachment_category="my-category" id="' . $id . '" mla_rollover_text="{+title+}" mla_link_href="{+page_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"]' );
    ?>

    If you are still having trouble I would have to see the complete source code for your attachment.php file and know what theme you are using. I also need the complete text of the [mla_gallery] shortcode that composes the gallery you are starting from.

    Regarding my long term plans, all I can say is that I am still actively developing and supporting the plugin for the foreseeable future. Donations are welcome; I have no plans for a for-profit version. When I decide to move on I will make every effort to find some person or organization to carry on the work.

    Thread Starter TallSam

    (@tallsam)

    No more white screen, must have been the mixture of quotes… I’m using the travel blogger theme.

    The following line gives me the correct ID but does not give me the category. I’m not sure what you mean by ‘you have not set them up in the [mla_gallery] shortcode that links to this page’. Where and how do I do that?
    <?php echo ‘$_REQUEST = ‘ . var_export( $_REQUEST, true ) . “
    “; ?>

    With categories not working, I put the category in manually as you suggested and so the next button cycled me through all the ids in the category. However, I always see the same image, and the url does not change as I would expect it too. I was hoping to go from:
    https://tall.life/?attachment_id=2178
    to
    https://tall.life/?attachment_id=2179
    but instead go to:
    https://tall.life/carstoosmall/?current_id=2179&attachment_category=tall-side

    How can I make the next button do what I was hoping for?

    Thanks,
    Sam

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and for trying some of the experiments I suggested. Adding the category manually and using the get_the_ID();
    function were two experiments I suggested to track down the “white screen of death”; they are not part of the final solution.

    If you have not already done so I encourage you to build the example I started with; the “Cloud and Gallery for Single Image” and “Single Image from Cloud and Gallery” pages. Study it carefully – it solves the “you have not set them up in the [mla_gallery] shortcode that links to this page” problem.

    In your [mla_gallery] shortcode you must add parameters that take the attachment_category and attachment_ID values for each gallery item and add them to the link that goes from the gallery to the Attachment Page. That is done in the mla_link_href parameter, and you must add something similar to your [mla_gallery] shortcode.

    If you want to continue working with your own [mla_gallery] and attachment.php application you can try adding this mla_link_href parameter to your [mla_gallery] shortcode:

    mla_link_href="{+pagelink_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"

    Then, go back to this do_shortcode in your attachment.php file:

    <?php echo do_shortcode(' [mla_gallery mla_output="next_link,wrap" mla_link_text="Next Image &rarr;" attachment_category="{+request:attachment_category+}" id="{+request:current_id+}" mla_rollover_text="{+title+}" mla_link_href="{+page_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"]' ); ?>

    Let me know how that works. If you are still having problems, please post the entire text of the [mla_gallery] shortcode you are using to pick the image you want.

    Thread Starter TallSam

    (@tallsam)

    Hey, I think we have it!
    And I think I understand: The id and category are being stored in the url, so the visitor has to arrive at a url with this info or the next link won’t work properly. So this means that when I send it out to social media, etc., I should provide the longer url, right?:
    https://tall.life/?attachment_id=2178?current_id=2178&attachment_category=tall-side

    I am very pleased to have it working and I thank you kindly for your patience!

    Below is my mla gallery shortcode as well as the do_shortcode for my attachments.php file, FYI.

    Thanks,
    Sam

    [mla_gallery attachment_category='tall-side' columns='3' orderby=date order=desc posts_per_page='40' mla_link_href="{+pagelink_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}" mla_link_attributes="{+template:target=({+custom:_gallery_link_target+}|_self)+}" mla_link_class="{+template:({+custom:_gallery_link_additional_css_classes+})+}"]
    <?php echo do_shortcode(' [mla_gallery mla_output="next_link,wrap" mla_link_text="Next Image &rarr;" attachment_category="{+request:attachment_category+}" id="{+request:current_id+}" mla_rollover_text="{+title+}" mla_link_href="{+pagelink_url+}?current_id={+attachment_ID+}&attachment_category={+query:attachment_category+}"]' ); ?>
    Plugin Author David Lingren

    (@dglingren)

    Congratulations! Thanks for posting the full text of your shortcodes so others can benefit from them. I appreciate your persistence in working through the details of your application with me.

    Regarding your social media question, yes – you “should provide the longer url” that includes the category and ID information.

    I am marking this topic resolved, but please update it if you have problems or further questions about using the mla_link_href parameter to pass information from one shortcode to another. Thanks again for an interesting question and for your interest in the plugin.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Link to next image in MLA category?’ is closed to new replies.