Topic: Customising output with shortcode attributes | WP Masonry Layout

Customising output with shortcode attributes

Home Forums Pro Version Customising output with shortcode attributes

This topic contains 10 replies, has 2 voices, and was last updated by  Masonry Guy 4 months, 1 week ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #3382 Reply

    Patabugen

    Hey,

    I wanted to be able to customise my Masonary Layout using shortcode attributes, rather than creating a new shortcode for every use case.

    I don’t believe this was possible, so I’ve added the following code to make it possible. It does hack the core of the plugin so I’d be interested to know either if it may be incorporated into the official release, or if there’s a way of doing it without hacking the core.

    In wp-masonary-layout-pro/plugin_interface.php around line 133 after:

    if (array_key_exists($shortcodeId, $shortcodesData)){ // Check if requested shortcode is in our record.
    	$shortcodeData	= $shortcodesData[$shortcodeId];

    Add:

    // See whether we've over-ridden any settings in GET (but only allow over-riding settings
    // which are actually used)
    foreach ($shortcodeData as $key => $value) {
    	if (isset($_GET[$key])) {
    		$shortcodeData[$key] = $_GET[$key];
    	}
    }

    In wp-masonary-layout-pro/includes/client/wmlp_container.php around line 6 replace:
    $link = admin_url('admin-ajax.php?action=wmlp_load_posts&shortcodeId='.$shortcodeId);
    with:

    
        $linkSettings = $atts;
        $linkSettings['action'] = 'wmlp_load_posts';
        $linkSettings['shortcodeId'] = $shortcodeId;
        unset($linkSettings['id'], $linkSettings['name']); // Remove the spare 'id' and 'name' fields
        $link               = admin_url('admin-ajax.php?'.http_build_query($linkSettings));
    

    I can now use a shortcode such as:
    [wmls name="All Blog Posts" id="1" wmlo_post_category="1340"]

    This seems to work for all my use-cases. I’d welcome any feedback. Don’t forget if you do this you won’t be able to updated the plugin without having to re-introduce these changes, so make sure you know what you’re doing.

    #3449 Reply

    Masonry Guy
    Keymaster

    Hi Patabugen,

    It will be great addition for the plugin. Thank you so much for your suggestion and the code. I will try to keep this in upcoming release.

    Thanks

    #9852 Reply

    Tim

    Is this a feature I need really bad and urgently, so I was super happy to find this hack, but unfortunately I can’t make it work following the description, can any of you help me out?

    I simply need to be able to alter what category the shortcode gets directly.

    Thank you
    Tim

    #9889 Reply

    Masonry Guy
    Keymaster

    Hi Tim,

    The above hack is for categories only. For this we have now generic shortcode features. Generic shortcode now allows you to use it directly in category.php file and it will take the category id. So this hack is not needed now.

    Regarding generic shortcode, you can check Topic #5 here http://www.masonrylayout.com/documentations/

    Thanks

    #9901 Reply

    Tim

    Ah I see, okay thanks for the quick reply!

    #11432 Reply

    Frank Torres

    Can this be used to filter by ‘author’? i.e. I’d like to display only images/posts from a particular user.

    (FYI, I’ve tried working in $_GET[‘aithorid’] to filter the output in my custom layout, but $_GET isn’t recognized in its output, probably due to the AJAX.)

    #11434 Reply

    Masonry Guy
    Keymaster

    Hi Frank,

    Ya this can be done. If you want to use this in your author template (http://yoursiteurl.com/author/AUTHOR_SLUG), you can directly use the generic shortcode and keep it in the template. Regarding generic shortcode, you can check Topic #5 here http://www.masonrylayout.com/documentations/ and check this video as well https://www.youtube.com/watch?v=ZFPhnysfRYk

    For normal shortcode, you can use this custom query box.
    author=12

    Where 12 is the author id you want to use for.

    Thanks

    #11435 Reply

    Frank Torres

    Thanks for the speedy reply, Keymaster! I’ve been digging through the documentation and feel light I’ve very close. I’d rather not set my shortcode as generic because this code layout is just for images. I see where I can use the custom query box, but I need this to display for ANY ONE of my users on the fly, not JUST ONE. Basically I have a Latest Pics page and want to give viewers the option to click on the poster’s name which I’ve coded to have a link with their author ID like so:

    /latest-pics/?authid=6

    BUT because it’s AJAX and the actual layout is served from the WP admin, I can’t get the “authid” in the URL to affect the content. Help?

    #11456 Reply

    Masonry Guy
    Keymaster

    Hi Frank,

    It is not possible to alter the query based on the $_GET variable. Since it is ajax based, those $_GET variable are not readable from ajax request.

    Thanks

    #13274 Reply

    Frank Torres

    Hi Keymaster, I had previously gotten author sorting to work by adding a php variable to the admin_url(‘admin-ajax.php?action=wmlp_load_posts&shortcodeId=’.$shortcodeId) in wp-masonary-layout-pro/includes/client/wmlp_container.php

    Of course that hack got wiped out in the latest plugin update. Can you give me an idea what php variable can be added to affect admin-ajax.php to only display posts by one author? And is it by author ID or name?

    Thanks!!

    #13276 Reply

    Masonry Guy
    Keymaster

    Hi Frank,

    I believe you are using pro version here and there is custom query box in the shortcode create/edit section.

    There you can just keep author={author_id} . Here {author_id} should be author’s user id. This should be number. For example. 1

    Hope this helps.

    Thanks

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Customising output with shortcode attributes
Your information: