WordPress.org

Ready to get started?Download WordPress

Forums

Media Library Assistant
[resolved] template query for att. tags (7 posts)

  1. gerald@WPcustoms
    Member
    Posted 1 year ago #

    Hello David,
    me again ;)

    I came across another difficulty.
    I got the following structure in mind:
    images are IPTC-tagged and get the according Att. Tag which works fine.
    images are not attached to any page.

    I want to list all attachment tags on the frontend in some kind of dropdown menu.

    the according keyword page (site.com/attachment_tag/keyword1/) should display all images which contain that specific tag.
    so I created a template taxonomy-attachment_tag.php which does this:
    <?php echo do_shortcode("[mla_gallery]"); ?>

    the problem is that I get all images listed on that page. ( due to [mla_gallery].)
    instead it should list only the KEYWORD1 images.
    Do you know how to forward the selected keyword (from the dropdown) into the mla_gallery shortcode? I can create a template for every keyword using the query from your documentation but I`ll have more than 200 keywords.

    Do you have a hot tip for me how to solve this?
    Or maby you got another idea how to show images according to their keywords without creating a page for every keyword.
    Thanks in advance for taking the time.
    Gerald

    http://wordpress.org/extend/plugins/media-library-assistant/

  2. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    Well, I can only speak in general terms without knowing all the details about your site, your theme and so forth.

    You need two pages:

    1) Contains the drop-down list with all the attachment tags. This would be wrapped in a form with a Submit button that sends the selection to a page that displays categories with the desired tag.

    2) Contains logic that adds the selected tag value to an [mla_gallery] shortcode to display the result. The selected value would be in the $_REQUEST array. The gallery display would be something like:

    <?php
    $tag = $_REQUEST['attachment_tag'];
    echo do_shortcode("[mla_gallery attachment_tag='{$tag}]'");
    ?>

    I created a taxonomy-attachment_tag.php page with this logic and then called it with http://site.com/?attachment_tag=artisan - it worked just fine. Sending the value from a form and dropdown list is somewhat different but that gives you the basic idea.

    For the Twenty_Eleven theme the whole page looks like:

    <?php
    /**
     * The template used to display Attachment Tag Archive pages
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    
    get_header(); ?>
    
    		<section id="primary">
    			<div id="content" role="main">
    
    				<header class="page-header">
    					<h1 class="page-title"><?php
    						printf( __( 'Attachment Tag Archives: %s', 'twentyeleven' ), '<span>' . $_REQUEST['attachment_tag'] . '</span>' );
    					?></h1>
    				</header>
    
    				<?php twentyeleven_content_nav( 'nav-above' ); ?>
    
    				<?php $tag = $_REQUEST['attachment_tag']; echo do_shortcode("[mla_gallery attachment_tag={$tag}]"); ?>
    
    				<?php twentyeleven_content_nav( 'nav-below' ); ?>
    
    			</div><!-- #content -->
    		</section><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I hope that gets you started. Thanks for the question and for using the plugin.

  3. gerald@WPcustoms
    Member
    Posted 1 year ago #

    Hi David,

    thanks a lot for your input and detailed explanation.
    I created a function which creates the dropdown and returns this:

    <form id="post_tag" name="post_tag" method="get" action="">
        <select name="post_tag" class="postform">
            <option value="keyword">keyword</option>
            <option value="keyword2">keyword2</option>
            <option value="keywordz">keywordz</option>
        </select>
    <input type="submit" id="submit" name="submit" value="GO">
    </form>
    
    <?php
    $tag = $_REQUEST['post_tag'];
    echo do_shortcode("[mla_gallery post_tag={$tag}]");
    ?>

    I got these codes on the same template (dropdown + MLA shortcode).
    I know I'm missing just a small thing to forward the input value to the $_REQUEST variable but currently I`m lost.

    thanks for every tip.

  4. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    Gerald,

    You're on the right track. Your original post was for attachment_tag but your code example is for post_tag; maybe that's your problem.

    I expanded my example to incorporate your form:

    <?php
    /**
     * The template used to display Attachment Tag Archive pages
     *
     * @package WordPress
     * @subpackage Twenty_Eleven
     * @since Twenty Eleven 1.0
     */
    
    get_header(); ?>
    
    <section id="primary">
        <div id="content" role="main">
            <header class="page-header">
                <h1 class="page-title">
                    <?php
                    printf( __( 'Attachment Tag Archives: %s', 'twentyeleven' ), '<span>' . $_REQUEST['attachment_tag'] . '</span>' );
                    ?>
                </h1>
            </header>
            <?php twentyeleven_content_nav( 'nav-above' ); ?>
            <?php
            $tag = $_REQUEST['attachment_tag'];
            echo do_shortcode("[mla_gallery attachment_tag={$tag}]");
            ?>
            <form id="attachment-tag-form" method="get" action="">
                <select name="attachment_tag" class="postform">
                    <option value="artisan">artisan</option>
                    <option value="attention">attention</option>
                    <option value="another-tag">another tag</option>
                </select>
                <input type="submit" id="submit" name="submit" value="GO">
            </form>
            <?php twentyeleven_content_nav( 'nav-below' ); ?>
        </div>
        <!-- #content -->
    </section>
    <!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    The name="attachment_tag" attribute in the select tag names the variable that shows up in $_REQUEST. When you click the "GO" button, the resulting URL is http:site.com/?attachment_tag=another-tag&submit=GO and the resulting page shows the images tagged with another-tag. Note that you want the slug/name field in your value attributes.

    I hope that gives you what you need.

  5. gerald@WPcustoms
    Member
    Posted 1 year ago #

    David,
    it works!! method="get" was the problem.
    with GET the option value is not send to the variable thus I always ended up with an invalid tax query due to the empty string.
    method="post" does the job without problems.

    learned my lesson with GET and POST in this example :)
    thanks again for helping out!

    btw about taxonomies:
    You mind me asking about your intention for the att. tags and att. categories?
    they all are taxonomies for the 'attachment' post-type as far as I get it.
    I understand it as 4 unique taxonomies to categorize attachments.
    (post_tag, attachment_tag, post_category, attachment_category)

    Is there a difference between post_tag\category and attachment_tag\category? (except the tag\category metabox difference)
    I'm fine with one taxonomy - just want to make sure that it doesnt matter which one Im going to use.

  6. David Lingren
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for this update - I'm happy you've got a success. In my example above GET works and POST does not; which one to use depends on the context the form is placed in.

    With respect to taxonomies, WordPress has two built-in taxonomies; "Categories" (slug category) and "Tags" (slug post_tag). These are traditionally used to classify posts and pages, but they don't apply to attachments. You can register them for attachments on the Settings/Media Library Assistant screen.

    For your convenience, MLA provides two custom taxonomies, "Att. Category" (slug attachment_category) and "Att. Tag" (slug attachment_tag). You can turn these on and off on the Settings/Media Library Assistant screen.

    You can define additional custom taxonomies in your own PHP code, or use one of the many plugins that provide that functionality.

    If you want to classify your posts, pages and attachments using exactly the same set of values, you can use "Categories" and/or "Tags". If you want to classify attachments with a different set of values, use "Att. Category" and/or "Att. Tag". For example, you might want to tag all you images by location or camera type, but that doesn't make sense for posts and pages.

    Which taxonomy (or taxonomies) to use depends on the structure of your site and application; there's no fixed rule. Here's a bit more information on the subject:

    Question for Media Library Assistant users

    I hope that helps. Thanks again for the questions and for using the plugin.

  7. gerald@WPcustoms
    Member
    Posted 1 year ago #

    David,
    thanks for your insights and helpful reply.
    you should get an "dedicated developer" badge for your profile :)

    keep up the good work.
    Gerald

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.