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

    (@dglingren)

    Thanks for this intriguing question. The short answer for the current MLA version is no, there’s no way to add PHP code to the Gallery template.

    I have thought about something like this from time to time, but the idea of allowing people to enter executable code strikes me as risky at best. I would hate to be accused of enabling a disaster!

    That said, I would like to hear more about what you have in mind. If there is a valid requirement and a way to do it safely I will consider adding it to my list of ideas for a future release.

    I hope to hear more about what you have in mind. Thanks again for your interest and for the question.

    Thread Starter steacha

    (@steacha)

    Thanks for the answer, David.

    I was reading through many posts involving PHP coding that I wondered where indeed would be the right place to make a modification requiring me to display all the custom fields created for a library item without having to explicitly name them using the [+custom:my_custom_field_name+] notation in the template.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for this additional detail; that’s an application I hadn’t thought of.

    It would be straightforward to create a new “pseudo value”, such as “custom:ALL_CUSTOM”, which would contain a dump of the custom fields for an item. This would be like the ALL_IPTC, ALL_EXIF and ALL_PDF pseudo values in the current MLA version. Have you tried those, and would a new pseudo value along those lines be sufficient?

    One problem I can think of is formatting; it’s hard to do a proper job given the variety of custom field content. A simple dump into a string value is easy enough, but if you want something with HTML markup, such as a table or a list, that’s harder.

    I’ll think it over. Any additional details you have time to share would be appreciated. Thanks for your help.

    Thread Starter steacha

    (@steacha)

    I am thinking that ALL_IPTC, ALL_EXIF and ALL_PDF would not work because they would contain information in addition to the custom fields, correct? But, in this scenario, the custom fields are the only ones needed.

    Would the following work for formatting?

    <div class="custom_field">
      <div class="name">custom field name</div>
      <div class="value">custom field value</div>
    </div>

    Or even better:

    <dl class="custom_field">
      <dt class="name">custom field name</dt>
      <dd class="value">custom field value</dd>
    </dl>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Plugin Author David Lingren

    (@dglingren)

    Thanks for the additional information. I’m sorry if my earlier post was not clear. I was referring to the ALL_IPTC, ALL_EXIF and ALL_PDF pseudo values as examples of what the output would look like. I was proposing to develop a new pseudo value, “custom:ALL_CUSTOM”, that would produce a similar display but would contain (only) the custom field information.

    In any case, your formatting proposals imply that a simple dump of the values would not be sufficient (although I may do it anyway). I will have to give this some more thought and see what I can come up with. I will leave this topic unresolved for now and update it when I have a better idea of how to proceed. Thanks for getting me started on this.

    Thread Starter steacha

    (@steacha)

    My apologies, I meant to also mention that ALL_CUSTOM would indeed do the trick (as opposed to the other ones, thanks for clarifying), but somehow forgot because I wanted to expand on the formatting.

    In any case, thanks for considering this, David, but for the time being where in the code would I need to make my PHP modifications to do what I explained earlier (displaying all custom fields as opposed to naming them directly in the template)?

    Plugin Author David Lingren

    (@dglingren)

    I will work on the ALL_CUSTOM feature, which I might be able to finish in a few days as part of my next planned release.

    When you say “where in the code would I need to make my PHP modifications“, are you referring to the code in the MLA plugin that processes the [mla_gallery] shortcode, or code in your theme that formats the page on which the gallery appears?

    If you are contemplating changing the plugin code itself, perhaps I can substitute a filter you can hook so your modifications won’t get lost every time there’s a new plugin release.

    Thread Starter steacha

    (@steacha)

    I sort of assumed I would have to change the plugin code itself, but yes, a hook might make life easier (I’ve never used one, but I am thinking it cannot possibly be hard to implement).

    Plugin Author David Lingren

    (@dglingren)

    I think adding one or more hooks to the plugin code will let you accomplish your goal in a way that’s safe, maintainable and of use to other plugin users. Let me see what I can do; thanks for a stimulating dialog!

    Plugin Author David Lingren

    (@dglingren)

    I think adding one or more hooks to the plugin code will let you accomplish your goal in a way that’s safe, maintainable and of use to other plugin users. Let me see what I can do; thanks for a stimulating dialog!

    Plugin Author David Lingren

    (@dglingren)

    I have released version 1.51, which adds and documents 25 filters in the [mla_gallery] shortcode to give you complete control over gallery content from PHP code in your theme or other plugins. I’ve also implemented the “ALL_CUSTOM” pseudo value.

    I’ve included a working example, based on your custom fields requirements. It’s a small stand-alone plugin you can add to your site and customize to fit your application.

    I hope you will find this new feature useful. If you have any problems with it, further questions or suggestions for improvement, let me know. Thanks again for your interest and for motivating this enhancement.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom Fields & PHP’ is closed to new replies.