• Resolved Julie

    (@habannah)


    Hi David,

    I’ve been trying to figure out how to exclude the featured image from my post gallery, since it’s displayed elsewhere on the page. The problem is that I can’t simply exclude by id since this is a template, so I don’t know the id yet. I’ve been through all the documentation, including substitution parameters and example plugins, and I can’t seem to find what I need. I’ve found workarounds that would probably get me there, or php filters that might do the job, but I’d much prefer doing it in my shortcode template. Is there a solution you can suggest?

    Here’s the base code I’m working with:

    [mla_gallery post_parent=current]

    I’d like to be able to do something like this:

    [mla_gallery post_parent=current exclude=featured]

    Thanks!

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

    (@dglingren)

    Good to hear from you again! Thanks for an interesting question.

    The best solution I can think of is adding a few lines of code to one of the existing MLA example plugins, “MLA Substitution Parameter Hooks Example”. This example already provides a “parent:” prefix that returns a number of values required by earlier support topics. Down around lines 321-325 you can find:

    
    if ( property_exists( $parent, $value['value'] ) ) {
    	$custom_value = $parent->$value['value'];
    } elseif ( 'permalink' == $value['value'] ) {
    	$custom_value = get_permalink( $parent );
    }
    

    You could add another elseif clause and some code to get the Featured Image (if it exists). Then, you could code something like:

    
    [mla_gallery post_parent=current exclude={+parent:featured+}]
    

    To use the new value in your shortcode template. To find the example plugin, navigate to the Settings/Media Library Assistant Documentation tab and click the new “Example Plugins” button. Enter “substitution” in the text box and click “Search Plugins”. You should see the example plugin.

    The “MLA Substitution Parameter Hooks Example” plugin is the one you want. You can hover over the plugin name and click the “Install” rollover action to add it to your site. Then, go to the Plugins/Installed Plugins admin submenu, find the plugin and activate it.

    I am traveling until next Thursday. If you need more specific guidance I can add the code and update the example plugin in the MLA Development Version.

    Plugin Author David Lingren

    (@dglingren)

    Please ignore the above suggestion. I frequently confuse an item’s parent with the post/page in which the [mla_gallery] shortcode appears. The {+parent:featured+} solution will not work.

    I did develop and test a solution that does work, but the code changes in the example plugin are more complex. With the new solution you can code:

    
    [mla_gallery post_parent=current exclude={+page:featured+}]
    

    I will update the example plugin and upload a new Development Version as soon as I can. Thanks for your understanding and your patience.

    Thread Starter Julie

    (@habannah)

    Thank you so much, David! I appreciate all your help, as always!! Have a great week — looking forward to hearing from you again in a few days ??

    • This reply was modified 8 years, 1 month ago by Julie.
    Thread Starter Julie

    (@habannah)

    The updated example plugin works perfectly. Thanks very much for everything, David!!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for working with me offline to test the updated mla_substitution-parameter-hooks-example.php example plugin. I am happy to hear it works in your application.

    I have uploaded a new MLA Development Version dated 20161027 that contains the updated example plugin. There are no changes from the version I sent you so you do not need to install the new Development Version.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude Featured Image from MLA Gallery’ is closed to new replies.