Provo a postare script completo, grazie
codice:<script type="text/javascript" > jQuery(document).ready(function() { //populate_home_posts(4); jQuery('#menuCategoryNews li').click(function(){ jQuery('#menuCategoryNews li').removeClass('currentCat'); jQuery(this).addClass('currentCat'); populate_home_posts(jQuery(this).data('id')); }); jQuery('#menuCategoryNews li:nth-child(1)').trigger('click'); setInterval(function() { if(jQuery('#mainNewsImage div').length > 1) jQuery('#mainNewsImage > div:nth-child(1)') .fadeOut(1000) .next() .fadeIn(1000) .end() .appendTo('#mainNewsImage'); }, 8000); }); function populate_home_posts(cat){ var ajaxurl = '/wp-admin/admin-ajax.php'; var data = { action: 'home_posts', cat: cat }; jQuery('#mainNewsImage').html('<div class="loading">Loading...</div>'); jQuery('#primaryNews .entry-title').html(''); jQuery('#primaryNews .entry-content').html(''); jQuery('#secondaryNews1 .secondaryNewsImage').html('<div class="loading">Loading...</div>'); jQuery('#secondaryNews1 .entry-title').html(''); jQuery('#secondaryNews1 .entry-content').html(''); jQuery('#secondaryNews2 .secondaryNewsImage').html('<div class="loading">Loading...</div>'); jQuery('#secondaryNews2 .entry-title').html(''); jQuery('#secondaryNews2 .entry-content').html(''); jQuery.post(ajaxurl, data, function(response) { jQuery('#mainNewsImage').html(''); jQuery('#primaryNews .entry-title').html(''); jQuery('#secondaryNews1 .secondaryNewsImage').html(''); jQuery('#secondaryNews1 .entry-title').html(''); jQuery('#secondaryNews2 .secondaryNewsImage').html(''); jQuery('#secondaryNews2 .entry-title').html(''); jQuery.each(response, function(i, item){ switch(i){ case 0: if(item.thumbnail){ var imgContent = '<div><a href="'+item.permalink+'"><img src="'+item.thumbnail+'" title="'+item.title+'" alt="'+item.title+'" /></a></div>'; for(var g in item.gallery){ imgContent += '<div style="display:none"><a href="'+item.permalink+'"><img src="'+item.gallery[g][0]+'" title="'+item.title+'" alt="'+item.title+'" /></a></div>'; } jQuery('#mainNewsImage').html(imgContent); } jQuery('#primaryNews .entry-title').html('<a href="'+item.permalink+'">'+item.title+'</a>'); jQuery('#primaryNews .entry-content').html(item.excerpt); break; case 1: if(item.thumbnail) jQuery('#secondaryNews1 .secondaryNewsImage').html('<a href="'+item.permalink+'"><img src="'+item.thumbnail2+'" title="'+item.title+'" alt="'+item.title+'" /></a>'); jQuery('#secondaryNews1 .entry-title').html('<a href="'+item.permalink+'">'+item.title+'</a>'); jQuery('#secondaryNews1 .entry-content').html(item.excerpt); break; case 2: if(item.thumbnail) jQuery('#secondaryNews2 .secondaryNewsImage').html('<a href="'+item.permalink+'"><img src="'+item.thumbnail2+'" title="'+item.title+'" alt="'+item.title+'" /></a>'); jQuery('#secondaryNews2 .entry-title').html('<a href="'+item.permalink+'">'+item.title+'</a>'); jQuery('#secondaryNews2 .entry-content').html(item.excerpt); break; } //console.log(item.title); }); }); } </script>

Rispondi quotando