• Resolved morchant

    (@morchant)


    Hi,
    with this plugin I can do anything, and it just fits my needs.
    I’m stuck here with [mla_gallery] short code. I want to get URL (only URL) of images from specific Category.

    For example, I created the category called “Sport” and want to get URL of all images from “Sport” category.

    When I run this code, I do not get any result:

    echo do_shortcode( "[mla_gallery category_name='sport'" );

    But when I run this shortcode
    echo do_shortcode( "[mla_gallery s='sport'" );

    I do get results, but I do not get URLS but a lot of another HTML code.

    How this can be implemented?

    Thank you!

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

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

    (@dglingren)

    It’s good to hear you are finding MLA useful; thanks. I think I understand your question, but I want to expand on it to make sure I get it right.

    When you say ‘all images from the “Sport” category‘, I assume you went to the Settings/Media Library Assistant General tab and checked the Support box for the Categories taxonomy. Then, you assigned one or more attachments to the Sport category. If that’s right, your category_name='sport' parameter should work, although it’s possible that the missing “]” at the end of your shortcode is causing trouble.

    When you say “want to get URL of all images” do you really mean just the URL, e.g., http::mysite.com/wp-content/uploads/my-image.jpg? your example uses echo to add the results of your shortcode to the page, so you might want a complete hyperlink instead, e.g.:

    <a href="http::mysite.com/wp-content/uploads/my-image.jpg">My Image</a>

    If you want a list of hyperlinks, you probably want some HTML around it such as an unordered list (< ul >). You can use the a custom template to customize the HTML or just add itemtag, icontag and captiontag parameters to the shortcode. For example, to change the gallery markup to use div, span and p tags: [mla_gallery itemtag="div" icontag="span" captiontag="p" columns=1]. Here’s an earlier support topic with more ideas:

    Simple List

    If you really want “raw” URLs, you can try something like this in your PHP code:

    $gallery = do_shortcode( '[mla_gallery category_name="sport" size=full link=none mla_style=none]' );
    $count = preg_match_all( '/src=\"([^\"]*)\"/', $gallery, $mla_matches );
    if ( $count ) {
        foreach ( $mla_matches[1] as $match ) {
         echo sprintf( '<meta property="og:image" content="%1$s" />', $match ) . "\n";
        }
       }

    That last echo statement can be replaced with anything you want to do with the URLs returned from the preg_match_all function. The code above is adapted from this earlier topic which may give you other ideas as well:

    Pull Featured Image from MLA Gallery

    I hope that gives you what you need for your application. I will leave this topic unresolved until I hear back from you in case I have not understood your question. Thanks for your interest in the plugin.

    Plugin Author David Lingren

    (@dglingren)

    I hope the suggestions I gave in my earlier post helped you get the results you needed. Since I have not heard back from you I am marking this topic resolved. Please update it if you have any problems or further questions about category-specific URLs.

    Thanks for the question and for your interest in the plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get URL of images with from specific Category’ is closed to new replies.