• Resolved ratamatcat

    (@ratamatcat)


    Hi David,

    It’s been a while and I’m relieved to see you’re still the chief architect and support for MLA!

    You helped out previously with code fragment to generate a gallery using an Att Tag linking a series of media together:
    https://www.ads-software.com/support/topic/gallery-that-uses-the-image-title/

    My new question is: can this MLA gallery be made to only display on the media attachment page for the No. 1 media item?

    Reason is I also want to let users navigate to the other media pages in a gallery and these will all be a simpler pared back look to them, but with some pertinent information. Then they can navigate back to the No. 1 media page where there is more extensive ‘global’ gallery info along with the gallery as well.

    Thanks,

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

    (@dglingren)

    Good to hear from you again, and thanks for your link back to the work we did together.

    In the earlier topic we worked on some PHP code added to the template file for the “Media Page”. Is this still the approach you’re taking?

    The earlier topic introduced the use of menu_order to control the gallery order. When you write “the No. 1 media item” can this item be identified by looking for a menu_order value of 1 (or perhaps zero)?

    If you’re still using PHP code and the menu_order approach it should be a simple fix. If you post your current code I can probably be more specific. If things have changed, how do you identify “the No. 1 media item“?

    Any additional details or code fragments you can provide will be helpful; thanks. You can also contact me at my web site if an email exchange would be easier. I can post a summary here once we’ve found a solution. Thanks for your long-standing interest in the plugin.

    Thread Starter ratamatcat

    (@ratamatcat)

    Hi David!

    Yep it must use Menu Order. When I uploaded a set of files each media displays the value of zero. This doesn’t seem to be a problem because the media are displayed in the correct order I wanted, maybe due to the file suffix or the Title I entered?

    I didn’t touch the menu order value for any of them but tried a test on 3 media (all with menu order value of 0). I simply adjusted the value of only one of these media to 1 and it jumped to the end of the MLA gallery on the front web page. So this is the behavior I expected here.

    Here’s the earlier code you provided

    <?php
    $item_id = get_the_ID();
    $tags = get_the_terms( $item_id, 'attachment_tag' );
    $slug = '';
    foreach ( $tags as $tag ) {
    	if ( 0 === strpos( $tag->name, 'Portrayal:' ) ) {
    		$slug = $tag->slug;
    		break;
    	}
    }
    
    if ( !empty( $slug ) ) {
    	echo do_shortcode( sprintf( '[mla_gallery attachment_tag="%1$s"]', $slug ) );
    }
    ?>

    I look forward to your next ideas,

    Pls let me know if I can provided any other note etc from our earlier workings on this, if required.

    Thanks,

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and for the tests you’ve run with menu order. I want to make sure I understand your goal.

    You wrote “My new question is: can this MLA gallery be made to only display on the media attachment page for the No. 1 media item?

    I understand that to mean that currently the gallery appears on the attachment page for all items assigned to the tag. You want the gallery to appear only on the item having the special menu_order value, e.g., “1”. Is that right?

    You wrote “I simply adjusted the value of only one of these media to 1 and it jumped to the end of the MLA gallery on the front web page.” That’s expected; the default is orderby='menu_order,ID' order=ASC. If you want the number 1 item to appear first you can add orderby='menu_order DESC,ID' to your shortcode.

    Here is some updated code that should do what you want:

    <?php
    $post = get_post();
    $tags = get_the_terms( $post->ID, 'attachment_tag' );
    $slug = '';
    foreach ( $tags as $tag ) {
    	if ( 0 === strpos( $tag->name, 'Portrayal:' ) ) {
    		$slug = $tag->slug;
    		break;
    	}
    }
    
    if ( !empty( $slug ) && ( 1 === $post->menu_order ) {
    	echo do_shortcode( sprintf( '[mla_gallery attachment_tag="%1$s"]', $slug ) );
    }
    ?>
    

    I’ve changed the first line to get the entire post so menu_order is available. I’ve updated the test for gallery display to use the special ‘1’ menu_order value to filter the display. I haven’t actually run this code but the changes are modest.

    I am marking this topic resolved, but please update it if you have problems or further questions regarding the updated code. If I have not understood your goal, any clarification you provide will help. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display MLA gallery on the initial media attachment page’ is closed to new replies.