Gallery’s look differs when dynamically created with shortcode
-
I wanted to create a page where in one column I will have automatically generated list of all galleries in an album. Click would show selected gallery in the second column.
Code is pretty simple:
jQuery(document).ready(function($) { function createLink(text_content, shortcode) { var inputElement = document.createElement('a'); inputElement.textContent = text_content; inputElement.addEventListener('click', function(){ document.getElementById("gallery-field").innerHTML = shortcode; }); return inputElement; } var list = document.createElement('ul'); for(var i = 0; i < my_script_data.galleries_count; ++i) { var element = document.createElement('li'); var link = createLink(my_script_data.galleries[i]['title'], my_script_data.galleries[i]['shortcode']); element.appendChild(link); list.appendChild(element); } document.getElementById("menu-column").firstElementChild.firstElementChild.appendChild(list); if(my_script_data.galleries_count) { document.getElementById("gallery-field").innerHTML = my_script_data.galleries[0]['shortcode']; } });As you can see I set initial shortcode exactly as I would set any other. This code relies on data prepared by .php file. Shortcode generation looks like this:
$galleries[$ordinal]['shortcode'] = do_shortcode('[ngg src="galleries" ids="' . $galleryid . '" display="basic_thumbnail" thumbnail_crop="0"]');It seems to be working, all galleries from the album are available to choose and gallery in second column changes in regard to chosen element of list. But gallery view which opens after clicking any of the images in gallery is different at the beginning and after using any of links. First gallery has buttons to go to the next and previous images, number of images in the gallery displayed in the corner etc. If I choose any gallery from my list (even the same one as initial!) everything looks perfectly normal at the beginning. Gallery in the second column changes, but selecting the thumbnail displays only very basic view of one image, as if it wasn’t linked to the gallery. There is no buttons or any info about gallery. Even background is slightly different.
I wonder why it happens and what could I do to ensure that all of my galleries will be displayed properly. Right now it seems that any dynamic changes cause problems.
The topic ‘Gallery’s look differs when dynamically created with shortcode’ is closed to new replies.