• Resolved ceophoetography

    (@ceophoetography)


    I bet there’s a fairly simple method of accomplishing it, but my best efforts aren’t giving me the tags I want and I haven’t been able to find a support forum topic that addresses my issue. I’m trying to edit my attachment template (image.php) to include that particular attachment’s attachment tags in a manner similar to how a post ends with the tags assigned to the post.

    Posts use the WP core PHP code, the_tags, but for the attachments I need the MLA shortcode mla_tag_cloud. At first all I got was all of my tags, but once I added the taxonomy parameter “attachment_tag,” I began to get the attachment tags. But now I need to limit the cloud to the attachment. That’s what I can’t figure out how to do. I’m guessing I need the “parent” parameter, but how do I get it recognize the particular attachment. I’m using <?php do_shortcodeand want to put all of the parameters into the template file rather than mla_markup.

    After limiting the tag cloud to the current attachment, I’d like to suppress the variation in sizes. I’m currently using “largest=10 smallest=10,” but that breaks the appearance of the tags.

    Finally, I need to set the link of the tags to direct to the gallery page that I have set up, passing along the term.

    https://wordpress.org/plugins/media-library-assistant/

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

    (@dglingren)

    Thanks for the question and for the application details you included. You can get what you want with a shortcode like this one:

    [mla_tag_cloud taxonomy=attachment_tag ids=4399 smallest=10 largest=10 mla_link_href='{+page_url+}?current_slug={+slug+}']
    • The ids= parameter names the ID of the attachment. The cloud will contain the tags assigned to that attachment.
    • The mla_link_href= sets the destination for the links behind each term. You can substitute any URL you need for the {+page_url+} psrt that brings control back to the current post/page.
    • The current_slug={+slug+} passes the term slug to the destination post/page as a query argument. You can use any argument name and value you need.

    You wrote “that breaks the appearance of the tags” but you don’t say how. Can you give more details on that?

    Thread Starter ceophoetography

    (@ceophoetography)

    Thank you for your response.

    If I code an ID into my template file (image.php), then how will be able to specify for each attachment? If I have 1,000 attachments, then I need for MLA to “read” its ID or slug and build its tag cloud from the attachment tags for the tag in question. Basically, I need a dynamic application: each time that an attachment is opened, I want a tag cloud of that attachment’s terms to appear. Is there a way of doing that?

    As for the breaking of tag styles, I guess I’ll just have to figure out, based on my style sheet, the exact number of ems to assign the shortcode (as well as assigning a unit of em instead of pt or px). The way that it’s breaking is that the :before is not the same size as the link. Right now it’s just on my test server.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update.

    You wrote “If I code an ID into my template file (image.php)“; your image file should have some code to set the current post/attachment, so you can use something like get_the_ID() to retrieve the ID of the current item in the WordPress Loop. Then use it in a sprintf() that forms the shortcode parameters.

    As you’ve discovered, styling the cloud depends on your theme. You can use the parameters mla_link_attributes, mla_link_class and mla_link_style to assign class and CSS style attributes to your items, or use a custom mla_style and/or mla_markup template to make any changes you require. More information can be found in the Tag Cloud Display Content section of the Settings/Media Library Assistant Documentation tab.

    Thread Starter ceophoetography

    (@ceophoetography)

    Thank you, David, for all of your wonderful assistance. Using your code above as a starting point and consulting the documentation (as I’d been doing before posting here), I was able to get everything working the way I envisioned.

    <?php echo do_shortcode('[mla_tag_cloud mla_output=flat taxonomy=attachment_tag post_mime_type=image ids=' . get_the_ID() . ' largest=11 smallest=11 unit=px mla_link_href="' . esc_url( home_url( "/" ) ) . 'exhibiting-peace-offering/?current_item={+term_id+}&tax_input{{+query:taxonomy+}}{}={+slug+}&muie_per_page={+template:({+request:muie_per_page+}|20)+}" mla_rollover_text="Click to view more &quot;{+name+}&quot; photos"]' ); ?>

    It did not require the use of sprintf() at all.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Insert attachment's tags as tag cloud in image.php’ is closed to new replies.