Skip to content

Instantly share code, notes, and snippets.

@Sitebase
Created September 29, 2015 10:37
Show Gist options
  • Save Sitebase/8c7f44de3076efa34656 to your computer and use it in GitHub Desktop.
Save Sitebase/8c7f44de3076efa34656 to your computer and use it in GitHub Desktop.
Add comments based on meta data under each gallery entry in modern gallery template
/**
* Add specific meta field under each entry in the gallery
*
* styling can be done using:
* .reason {
* ...
* }
*
* Replace `meta.waarom` with something else to use another meta key
*/
window.bbbx_modules = window.bbbx_modules || []; // Make modules array if not yet exists
window.bbbx_modules.push(function(sandbox, $) {
var NAME = 'wpgreasonmeta';
var exports = {
NAME: NAME,
init: function() {
window._template = BBBX.template.parse;
BBBX.template.parse = this.parse;
},
parse: function(template, data) {
if(
data.hasOwnProperty('meta') &&
data.meta.hasOwnProperty('waarom') &&
template.indexOf('entry') > -1
) {
template = template.replace('</figure>', '</figure><div class="reason" style="text-align:center; padding: 10px"><%= meta.waarom %></div>');
}
return window._template.apply(this, arguments);
},
destroy: function() {
BBBX.template.parse = window._template;
}
};
return exports;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment