Support » Plugin: Media Library Assistant » Exclude an att tag from display on attachment page site front end

  • Resolved ratamatcat

    (@ratamatcat)


    Hi David,

    A while ago you provided code which worked with an Att. tag Gallery: term (so for example Gallery: nebula stars dust). I added this tag to all the uploaded media I wanted to form a particular MLA Gallery with your code.

    As this was an internal type of tag I wanted to prevent it from displaying on the attachment page site front end which you updated with some revised code:

    $output = array();
    foreach ( $terms as $term ) {
        if ( 0 !== strpos( $term->name, 'Gallery:' ) ) {
            $output[] = sprintf( '<a href=%1$s%2$s?my_taxonomy=%3$s&my_term=%4$s title="Gallery for %5$s">%5$s</a>', $site_url, $page_path, $taxonomy, $term->slug, $term->name );
        }
    }
    
    $output = "Tags: " . implode( ', ', $output );

    The revised part being

    if ( 0 !== strpos( $term->name, 'Gallery:' ) ) {

    This took out the Gallery: term tag from display on the attachment page front end.

    Now I want to add some more tags to be excluded and am uncertain of the syntax, have tried for example:

    if ( 0 !== strpos( $term->name, 'Gallery:', 'gallery control portrayal' ) ) {

    The new tag being of course gallery control portrayal.

    No huge success so far with my own attempts, the new tag and the original Att. tag Gallery: term are showing up on my site.

    Am I somehow able to add more tags to this setup?

    Thanks,

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

    (@dglingren)

    Good to hear from you again and thanks for the detailed description of your question; very helpful. It looks like you are referring to this earlier topic:

    Gallery that uses the image Title

    The strpos() function will only find one substring within a larger string, so you will need a separate function call or another test to exclude additional terms. In the above code the first substring, “Gallery:’, is a prefix that always appears at the start (position 0) of the larger string. Below are expanded examples that add your new term.

    First, if 'gallery control portrayal' is the entire term name you can code:

    if ( ( 0 !== strpos( $term->name, 'Gallery:' ) ) && ( 'gallery control portrayal' !== $term->name ) ) {
    

    If the new term always begins the name but something can follow it you can code:

    if ( ( 0 !== strpos( $term->name, 'Gallery:' ) ) && ( 0 !== strpos( $term->name, 'gallery control portrayal' ) ) ) {
    

    If the new term can appear anywhere in a larger name you can code:

    If ( ( 0 !== strpos( $term->name, 'Gallery:' ) ) && ( false === strpos( $term->name, 'gallery control portrayal' ) ) ) {
    

    I’ve added some parentheses to make the different parts of the test more readable. You can extend these examples to a few more terms before they become awkward.

    I hope this gives you the solution you seek. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above examples. Thanks for your continued interest in the plugin.

    Thread Starter ratamatcat

    (@ratamatcat)

    The code runs like a watch.

    As a followup and general question, is there a difference in choosing an Att tag or an Att category when needing a taxonomy for internal control? I am more or less just duplicating your previous recommendation of a tag (i.e. for linking the gallery media together).

    The purpose is simply to be able to point custom fields to a particular media – in this case the No. 1 media upload in a gallery of media. There I can place some field controls to customize elements of the gallery textual content. These fields don’t need to be on the media edit screen of all the gallery media, only the No. 1 screen.

    I suspect either an Att tag or Att category are equally suitable.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for confirming that the suggestions I made earlier are working for you.

    The decision between categories and tags is subjective and application-dependent. I have read that “Categories are structured and formal, like a table of contents. Tags are free-form and informal, like an index.” From the information you gave it looks like tags are the appropriate choice for your application.

    There are two other techniques you could consider: 1) you could define an additional taxonomy exclusively for holding the control information. That might simplify admin duties, or 2) you could place the control information in a separate custom field rather than a taxonomy.

    MLA would support either of these alternatives. You can have a look at the “MLA Custom Taxonomy Example” plugin to see what’s required to define a taxonomy of your own making. Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “taxonomy” in the text box and click “Search Plugins” to filter the table.

    Thread Starter ratamatcat

    (@ratamatcat)

    Thanks David I will look into that. So if I find myself needing to add more and more admin-type Att tags to my media and then needing to exclude them from the site front end, if I ‘defined an additional taxonomy’ it would exist outside the regular tags and prevent this need. It would display in WP sidebar for MLA as (My new Att. tag)

    Library
    Add New
    Att. Category
    Att. Tag
    My new Att. tag
    Assistant

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.