开发者

jQuery grabbing header results in empty content

I know this sounds weird. But I'm using the jQuery Cycle plugin with a WordPress site to pull in a custom post type as a banner image with content. For the pagination, I want the post title to be the link text, rather than your standard "1 2 3 4..." etc.

I managed to figure out how to do it - but now I have a fun new issue. When I pull the post title and pop it into the pagination link, my post content disappears. It would seem jQuery is grabbing what it finds, removes it, and pops the items it's looking for in the link button. Which is weird.

Anyway, would anyone know how to fix this? This is my jQuery code:

jQuery(document).ready(function ($) {
            $('#slideshow div.slide:first').fadeIn(1000, function() {
                $('#slideshow').after('<div id="pagination"><div id="page_inner"><ul>').cycle({
                    fx: 'scrollHorz',
                    speed: 500,
                    timeout: 0,
                    pager: '#pagination #page_inner ul',
                    pagerAnchorBuilder: function(idx, slide) { 
                        $('.slide_caption', slide).children('h3');
                        //alert($(slide).text());
                        return '<li><a href="#">' + $(slide).text() + '</a></li>';
                    }
                });
            });
        });

Basically, I want the jQuery to look in the slide_caption div, find the first <h3> tag and copy that text and pop it in for the link button text. It's finding it and doing it with the above code - but it's also stripping out all of the content in the slide_content div while doing so. and now it's pulling in the entire content of the post into the button, instead of just the <h3> tag.

An开发者_StackOverflow社区y help would be appreciated! Thank you :)


Looks like you're not grabbing the H3's text() and are instead pulling the entire text() from your slide.

pagerAnchorBuilder: function(idx, slide) { 
    return '<li><a href="#">' + $(slide).find('.slide_caption h3').text() + '</a></li>';
}

versus

pagerAnchorBuilder: function(idx, slide) { 
    $('.slide_caption', slide).children('h3'); // You're not doing anything with this
    //alert($(slide).text());
    // $(slide).text() => complete text from your slide parameter
    return '<li><a href="#">' + $(slide).text() + '</a></li>';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜