-
-
Save wp-lab/58ef11c28a0187db7104 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script async type="text/javascript"> | |
function loadDynamicCategories() { | |
$.getJSON('http://www.example.com/wp-admin/admin-ajax.php?action=wpl_ebay_store_categories&callback=?', function(data) { | |
$('#categories_wrapper').append('<ul></ul>'); | |
$.each(data, function(index) { | |
$('#categories_wrapper ul').append('<li id="'+data[index].cat_id+'"><a href="'+data[index].url+'">'+data[index].cat_name+'</a></li>'); | |
}); | |
}); | |
// add optional link to store home page at the top | |
$('#categories_wrapper ul').prepend('<li><a href="'+'[[ebay_store_url]]'+'">Store Home</a></li>'); | |
} | |
function loadjQuery() { | |
var head = document.getElementsByTagName("head")[0]; | |
var script = document.createElement("script"); | |
script.type = "text/javascript"; | |
script.src = "//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"; | |
head.appendChild(script); | |
waitUntiljQueryIsLoaded(); | |
} | |
function waitUntiljQueryIsLoaded() { | |
if ( typeof window.jQuery !== 'undefined' && window.jQuery ) { | |
if (typeof jQueryLoaded == 'function') { | |
jQueryLoaded(); | |
} | |
} else { | |
window.setTimeout( waitUntiljQueryIsLoaded, 100 ); | |
} | |
} | |
// payload - executed when jQuery has been loaded | |
function jQueryLoaded() { | |
jQuery(document).ready(function(){ | |
// load categories | |
loadDynamicCategories(); | |
}); | |
} | |
// init | |
loadjQuery(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
used on http://docs.wplab.com/article/139-how-to-use-dynamic-categories-in-your-ebay-listing