kimaldis on "[Plugin: NextGEN Gallery] Gallery template, access shortcode attributes"

ساخت وبلاگ

Using this shortcode to insert a gallery into a post:

[nggallery id=1 template=templatename foo=123 fee=456]

Is it possible to pick up the two custom attributes foo and fee, or any other custom attributes, in the gallery-template.ph?

https://wordpress.org/plugins/nextgen-gallery/

@kimaldis - There are no current methods to randomly create a template "attribute" that can then be used by a shortcode unless that attribute has a matching parameter in the shortcode itself.

Perhaps a clearer description of what you are wanting to display might help us direct you to a more "complete" shortcode?

There is also the following article related to NextGEN Gallery shortcodes you can find here: http://imagely.com/docs/nextgen-gallery-shortcodes/

Thanks!

- Cais.

Sorry, I maybe didn't explain myself that well. I've built a KA-template.php template, placed it in the correct place in themes. I insert it into a post using:

[nggallery id=1 template=KA]

I would like to be able to have some control over, say, the number of columns displayed in the post by using an attribute in the shortcode:

[nggallery id=1 template=KA columns=5]

but there doesn't seem to be a way to get at attributes in the shortcode from php code in the template file. Does that make more sense?

Mulling this over the weekend I couldn't see any immediately obvious way to do this so I a workaround. This code snippet searches for nggallery shortcodes in the post, checks the shortcode id against the gallery id handed to the template and pulls attributes from it if it matches. It will fall apart a bit if there are two galleries with the same id being shown in the page but I really can't see that happening in a sensible world.

global $post;
$patte = get_shortcode_regex();
$thisGalleryID = $images[0]->galleryid; // obscure place to get it but I can't find it in the rather badly documented $gallery object.
// grep all nggallery shortcodes in the post.
if ( preg_match_all( '/'. $patte .'/s', $post->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( 'nggallery', $matches[2] ) ) { $attributeStrings = $matches[3]; // an array of attribute strings, one for each shortcode found in the post. $found = false; foreach ($attributeStrings as $i => $attributes) { $attrs = shortcode_parse_atts( $attributes ); $id = $attrs['id'] or false; $columns = $attrs['columns'] or 5; $info = $attrs['info'] or false; // show the title banner to bottom of image $infohover = $attrs['infohover'] or false; // show/hide info bar on hover $downloadable = $attrs['downloadable'] or false; if ( $id == $thisGalleryID ) { // gid in the shortcode matches gid sent to this template? $found = true; break; } } if ( !$found ) { echo "couldn't find a shortcode match for this gallery ($thisGalleryID)<br>"; }
}

@kimaldis - Thanks for sharing your work-around ... also without knowing / seeing what your custom template is doing, did you look at the number_of_columns shortcode parameter as well?

- Cais.

Any time.

I didn't spot a columns count parameter so I added my own.

If I can be frank, I'm finding documentation at this level either sparse, sketchy or scattered. Things like the $gallery & $image objects seem to be largely undocumented and I can find nothing that resembles an API for NextGen. I've had to dig quite deep. I'm now looking into custom lightboxes and that's proving interesting too. Maybe you have some links that I may have missed?

I still have features to add but have a working version of the template. It uses the Isotope packery plugin. It will have sharing, purchase buttons, it already has download buttons. Working example here, if you're interested:

@kimaldis - Updating our documentation is definitely on our list of things to get accomplished as we do recognize it is indeed "sparse" in several places.

An "undocumented" note when it comes to shortcode parameters, almost every element you can find via the browser's developer tools in a specific Gallery Setting can be used as a shortcode parameter for that gallery ... just remove the display type reference.

For example: http://take.ms/VGn95 shows ... photocrati-nextgen_basic_thumbnails_number_of_columns et al.

So you would just use number_of_columns for the column count.

- Cais.

That's useful. Thank you very much.

I don't suppose you have any pointers towards getting going with custom lightboxes?

- K.

@kimaldis - Our "custom" option for the Lightbox Effects is basically a fill in the blanks approach. If you want to "hard-code" the trigger for your custom Lightbox library you would need to also create a custom template ... there are no parameters in any of our displays that can set a Lightbox at this time.

- Cais.

Looking at ng shortcode thing in gallery settings properly for the first time, it does seem like an odd way to deal with templates, doesn't it? You're effectively asking a user to select a gallery display type, which would show a gallery as a particular type, then select a template that will most probably show the gallery completely differently to the type selected. And no way to pass parameters to the template, other than those allowed in the gallery display settings. It's all very counter-intuitiveSurely a better way would be to allow a developer to add templates, along with parameters, to the display type list?

I mention this, partly because it's so odd and partly because oddness seems to thread it's way through Nextgen. From a standpoint, Nextgen is a bit of a mess. No offence intended.

From a developers' standpoint. Sorry.

@kimaldis - The template "system" is a NextGEN Legacy hold-over we maintain for backward compatibility, there is actually no real "template" system in the same sense with current NextGEN Gallery display types.

A developer should be easily able to create a "new" display type although it is a bit involved, here is a link to a "draft" document that goes through the details: https://0x18.us/creating-a-new-nextgen-display-type/

Perhaps this will be of better use ... and thanks for the feedback, it is much appreciated!

- Cais.

kimaldis
Member
Posted 1 minute ago #

That's an extremely useful link. Thanks.

I think the hardest thing in all of this is actually trying to find information like this. There should be a wiki or something. Or maybe there is?

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 167 تاريخ : شنبه 11 ارديبهشت 1395 ساعت: 14:52