Hey guys,

If you can help me with the fix (line: 9) below that would be great.

each() is causing the problem for me, as it's performing the code on
each <p> and not the total <p>'s. Can anyone suggest a solution?

// create a 'continue reading' - linked to the single post page -
if .scrollableItem's paragraph content exceeeds set quota
$(document).ready(function () {
    // set word limit
    var quota = 20;

        $('.scrollable .scrollableItem p').not('.wp-caption-text').not
('.postmetadata').each(function () {

                // count the no. of words in the post and assign to var 
totalWords
(fix: presently this counts no. of words in EACH paragraph. we need
no. of words in ALL paragraphs here.)
                var string = $(this).text();
        var count = string.split(" ");
        var totalWords = count.length;

        // set up post variables
        var postTitle = $(this).parent().find('h2').text();
        var postURL = $(this).parent().find('h2 a').attr('href');

        // if word limit is reached drop in a 'continue reading' link
        if (totalWords >= quota) {
                        $(this).parent().find('.postmetadata').before('<p
class="readMore"><a href=' + '"' + postURL + '"' + '>Continue
reading:' + postTitle + '</a></p>');

        };

    });

});

Thanks,
L

Reply via email to