Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Konrad Pilch
2,435 Points[SOLVED]Whats wrong here?
I have a carousel that should display 4 pieces of carouse. it works on my static version and now im putting it in wordpress.
Here how it looks like :
jQuery(function($){
// setup your carousels as you normally would using JS
// or via data attributes according to the documentation
// http://getbootstrap.com/javascript/#carousel
$('#carousel123').carousel({ interval: 4000 });
}());
jQuery(function($){
$('.carousel-showmanymoveone .item').each(function(){
var itemToClone = $(this);
for (var i=1;i<4;i++) {
itemToClone = itemToClone.next();
// wrap around if at end of item collection
if (!itemToClone.length) {
itemToClone = $(this).siblings(':first');
}
// grab item, clone, add marker class, add to collection
itemToClone.children(':first-child').clone()
.addClass("cloneditem-"+(i))
.appendTo($(this));
}
});
}());
I have checked in the dev toold and the script is connected. All the scripts work. It just the script it self doesnt work on he page, doesnt perform what it should do.
Whats worng with this code?
4 Answers
Joseph Szoke
15,087 PointsLike what Dylan said: if you are only seeing three show up you need to start your for loop at 0 (i =0). Remember that the first position in JavaScript starts at 0 not 1.
Otherwise post some error messages or link to the site and we can further help
Dylan Aresu
9,687 PointsWouldnt you set the middle parameter of the for loop to... for var i = 0; i < .carousel-showmanymoveone.length; i += 1 or for var i = 0; i < 4; i += 1 because you want 4 items, with the loop you use i'm sure it will only display 3.
Annet de Boer
900 PointsWhat is the error you get (or the unexpected result you see)?
Joseph Szoke
15,087 PointsPay attention to how many times you are loading jQuery. If I'm not mistaken jQuery gets loaded from the admin side of Wordpress as well which could cause some conflicts.
Also when building Wordpress locally it is best to use something like MAMP to mimic a server to help with testing in a live atmosphere.
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsHi, thank you for the answer. This code works on my static page. I found out that i had to replace all these $ with a jQuery text. Otherwise it will conflict with WordPress, as it worked on my local site.
But, anyways, i have few errors on this site, and i can't solve that problem. I came closer to it by replacing the add_action to something else, now it ish-works, but i still have the error and it doesnt work, the jQuery any JS. JS is dead there. Which is again strange because it worked on my static site and on another site i was doing.